/*
动态规划版本
*/classSolution{publicintuniquePaths(int m,int n){int[][] f =newint[m][n];for(int i =0; i < m; i ++){for(int j =0; j < n; j ++){if(i ==0) f[i][j]=1;if(j ==0) f[i][j]=1;if(i >0&& j >0)
f[i][j]= f[i -1][j]+ f[i][j -1];}}return f[m -1][n -1];}}
/*
dfs版本,会超时
*/int res =0;publicintuniquePaths(int m,int n){boolean[][] flag =newboolean[m][n];dfs(0,0, m, n, flag);return res;}int[] dx =newint[]{0,1};int[] dy =newint[]{1,0};privatevoiddfs(int i,int i1,int m,int n,boolean[][] flag){if((i == m -1)&&(i1 == n -1)){
res ++;return;}
flag[i][i1]=true;for(int j =0; j <2; j ++){int x1 = i + dx[j], y1 = i1 + dy[j];if(x1 >=0&& x1 < m && y1 >=0&& y1 < n &&!flag[x1][y1]){dfs(x1, y1, m, n, flag);}}
flag[i][i1]=false;}
不同路径/*动态规划版本*/class Solution { public int uniquePaths(int m, int n) { int[][] f = new int[m][n]; for (int i = 0; i < m; i ++) { for (int j = 0; j < n; j ++) { if (i == 0) f[i][j] = 1;