474. Ones and Zeroes
来源:互联网 发布:无线传感器网络 编辑:程序博客网 时间:2024/06/05 16:31
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 m0s
andn1s
respectively. On the other hand, there is an array with strings consisting of only0s
and1s
.
Now your task is to find the maximum number of strings that you can form with givenm0s
andn1s
. Each0
and1
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
.
class Solution {public: int findMaxForm(vector<string>& strs, int m, int n) { int f[m+1][n+1]; memset(f,0,sizeof(f)); int n0,n1; for(auto s : strs) { n0 = 0; n1 = 0; for(auto ch : s) { if(ch == '0') n0++; else if(ch == '1') n1++; } for(int i = m; i >= n0; i --) { for(int j = n; j >= n1; j--) { f[i][j] = max(f[i][j],f[i-n0][j-n1] + 1); } } } return f[m][n]; }};
0 0
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- 474. Ones and Zeroes
- CTF逆向工程入门_2
- mkimage使用详解
- AsyncTask
- hihocoder 1304 : 搜索一·24点(DFS+回溯)
- linux 文本处理命令cat
- 474. Ones and Zeroes
- hihoCoder
- 基于socket通信的局域网聊天室搭建(socket通信第四弹)
- Direct3D 光照练习
- C++ map的基本操作
- hihoCoder
- 计算语言学之语法理论
- QT 的信号与槽机制介绍
- 深入理解javascript原型和闭包(7)——原型的灵活性