Leetcode 474. Ones and Zeroes
来源:互联网 发布:php bin2hex写入文件 编辑:程序博客网 时间:2024/06/07 10:51
题目:
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.
class Solution {public: vector<int> countn(string s) { vector<int> re(2,0); for(int i=0;i<s.size();i++) { re[s[i]-'0']++; } return re; } int findMaxForm(vector<string>& strs, int m, int n) { int dp[m+1][n+1]={}; int len=strs.size(); for (auto s : strs) { vector<int> count = countn(s); for (int i=m;i>=count[0];i--) for (int j=n;j>=count[1];j--) dp[i][j] = 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
- Navicat Premium破解
- mysqlbinlog命令介绍
- Eloquent JavaScript 笔记 十七:HTTP
- Java篇--Java语言的基本语法3
- Elasticsearch5和head最新插件学习,JavaAPI demo
- Leetcode 474. Ones and Zeroes
- 刷清橙OJ--A1089.阶乘计算
- Unity 阻止手机熄屏
- JDK1.8的新特性——注解Annotation更多场景的使用
- PHP使用PDO调用sqlserver存储过程记录【分享个通用方法】
- Leetcode Add Binary
- Docker 安装
- 第三方登陆 ,微信扫码登陆
- AI Fintech 驱动智能金融时代到来