leetcode474

 1 public class Solution {
 2     public int findMaxForm(String[] strs, int m, int n) {
 3         if (strs == null || strs.length == 0) {
 4             return 0;
 5         }
 6         int[][] dp = new int[m + 1][n + 1];
 7         for (String s : strs) {    // 每个字符串只能用一次
 8             int ones = 0, zeros = 0;
 9             for (char c : s.toCharArray()) {
10                 if (c == '0') {
11                     zeros++;
12                 } else {
13                     ones++;
14                 }
15             }
16             for (int i = m; i >= zeros; i--) {
17                 for (int j = n; j >= ones; j--) {
18                     dp[i][j] = Math.max(dp[i][j], dp[i - zeros][j - ones] + 1);
19                 }
20             }
21         }
22         return dp[m][n];
23     }
24 }
原文地址:https://www.cnblogs.com/asenyang/p/11005830.html