-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay53.java
More file actions
28 lines (28 loc) · 826 Bytes
/
Day53.java
File metadata and controls
28 lines (28 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.Scanner;
public class Day53 {
public static int uniquePaths(int m, int n) {
int[][] dp = new int[m][n];
for (int i = 0; i < m; i++) {
dp[i][0] = 1;
}
for (int j = 0; j < n; j++) {
dp[0][j] = 1;
}
for (int i = 1; i < m; i++) {
for (int j = 1; j < n; j++) {
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
return dp[m - 1][n - 1];
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
for (int t = 0; t < T; t++) {
int M = scanner.nextInt();
int N = scanner.nextInt();
System.out.println(uniquePaths(M, N));
}
scanner.close();
}
}