publicintfindMaxForm(String[] strs, int m, int n){ int[][][] dp = newint[strs.length][m + 1][n + 1]; //设置base case int[] countBase = count0And1(strs[0]); for (int j = 0; j <= m; j++) { for (int k = 0; k <= n; k++) dp[0][j][k] = (j >= countBase[0] && k >= countBase[1]) ? 1 : 0; } for(int i = 1; i < strs.length; i++) { int[] count = count0And1(strs[i]); for (int j = 0; j <= m; j++) { for (int k = 0; k <= n; k++) { int a = count[0]; int b = count[1]; if(j < a || k < b) dp[i][j][k] = dp[i-1][j][k]; else dp[i][j][k] = Math.max(dp[i-1][j][k], dp[i-1][j-a][k-b]+1); } } } return dp[strs.length - 1][m][n]; }