提交时间:2023-12-08 13:12:29

运行 ID: 114497

# include <bits/stdc++.h> using namespace std ; vector <string> v ; int fmf ( vector <string> strs , int m , int n ) { vector < vector < int > > dp ( m + 1 , vector <int> ( n + 1 , 0 ) ) ; dp [0] [0] = 0 ; for ( string s : strs ) { int x = 0 , y = 0 ; for ( char c : s ) { if ( c == '0' ) { x ++ ; } else { y ++ ; } } for ( int i = m ; i >= x ; i -- ) { for ( int j = n ; j >= y ; j -- ) { dp [i] [j] = max ( dp [i] [j] , dp [i - x] [j - y] + 1 ) ; } } } return dp [m] [n] ; } int main ( ) { int x , m , n ; cin >> x >> m >> n ; for ( int i = 1 ; i <= x ; i ++ ) { string s ; cin >> s ; v . push_back ( s ) ; } cout << fmf ( v , m , n ) << endl ; return 0 ; }