【LeetCode】 474. Ones and Zeroes
来源:互联网 发布:vb什么时候吃效果好 编辑:程序博客网 时间:2024/05/17 15:35
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 mostonce.
Note:
- The given numbers of
0s
and1s
will both not exceed100
- The size of given string array won't exceed
600
.
Example 1:
Input: Array = {"10", "0001", "111001", "1", "0"}, m = 5, n = 3Output: 4Explanation: This are totally 4 strings can be formed by the using of 5 0s and 3 1s, which are “10,”0001”,”1”,”0”
Example 2:
Input: Array = {"10", "0", "1"}, m = 1, n = 1Output: 2Explanation: You could form "10", but then you'd have nothing left. Better form "0" and "1".
public class Solution { public int findMaxForm(String[] strs, int m, int n) { int[][] dp = new int[m + 1][n + 1]; for (String s : strs) { int[] count = new int[2]; for (int i = 0; i < s.length(); i++) { count[s.charAt(i) - '0']++; } for (int i = m; i >= count[0]; i--) { for (int j = n; j >= count[1]; j--) { dp[i][j] = Math.max(1 + dp[i - count[0]][j - count[1]], dp[i][j]); } } } return dp[m][n]; }}
0 0
- LeetCode 474. Ones and Zeroes
- [leetcode] 474. Ones and Zeroes
- LeetCode 474. Ones and Zeroes
- Leetcode-474. Ones and Zeroes
- [LeetCode]474. Ones and Zeroes
- 【LeetCode】 474. Ones and Zeroes
- LeetCode 474. Ones and Zeroes
- [leetcode]474. Ones and Zeroes
- Leetcode 474. Ones and Zeroes
- Leetcode 474. Ones and Zeroes
- leetcode 474. Ones and Zeroes
- [LeetCode] 474. Ones and Zeroes
- LeetCode: Ones and Zeroes
- [LeetCode] Ones and Zeroes
- Leetcode 474. Ones and Zeroes (Medium) (cpp)
- 第十一周:[Leetcode]474. Ones and Zeroes
- [Leetcode] 474. Ones and Zeroes 解题报告
- 474. Ones and Zeroes
- 2017美国数学建模MCM C题(大数据)翻译 “合作和导航”
- Eclipse常用快捷键
- 十年
- try{}catch(){}finally{}语句中return的执行情况
- Velocity中VelocityLayoutViewResolver类源码
- 【LeetCode】 474. Ones and Zeroes
- git创建本地仓库到推送gitlab
- 【codeforces 758A】Holiday Of Equality
- Git 项目分支管理
- 关于未来IT职业教育的思考
- windows(64位)下使用curl命令
- JAVAWEB+TOMCAT+MYSQL局域网服务器搭建简单流程
- 机器学习算法——线性回归
- 2017美国数学建模ICM D题翻译 在机场安检站优化乘客吞吐量