In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.
For now, suppose you are a dominator of m 0s and n 1s respectively. On the other hand, there is an array with strings consisting of only 0s and 1s.
Now your task is to find the maximum number of strings that you can form with given m 0s and n 1s. Each 0 and 1 can be used at most once.
Note:
The given numbers of 0s and 1s will both not exceed 100
The size of given string array won't exceed 600.
Example 1:
Example 2:
解法1:
这个的解释还算可以,来自于leetcode discuss:
C++
Java
解法2: 背包解法
此题实际上是一个背包问题,背包问题的本质是:
求一个最大或者最小,给定一定的限定条件。这里的限定条件是有限的0和1。
背包就构建一个n维数组,dp[i][j][k]表示前i个数,用jk两个限定条件所能达到的最大结果。
|
|