为啥不输出

Mapleleave  •  3年前


本地跑的


评论:

贴下代码把有没有大佬能看看

#include<iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int k, r, m, n;

const int K = 1500;
const int M = 510;

int f[K][M][M];
int v[K][2];

int tj(string str) {//0
    //cout << str << endl;
    int res = 0;
    for (auto c : str) {
        if (c == '0') res++;
    }

    //cout << res << endl;
    //printf("\n");
    return res;

}

int main() {
    cin >> k >> r >> m >> n;
    for (int i = 1; i <= k; i++) {
        string s;
        cin >> s;
        v[i][0] = tj(s);
        v[i][1] = s.size() - v[i][0];
        // cout << v[i][0] << " " << v[i][1] << endl;
    }


    for (int i = 1; i <= k; i++) {
        for (int j = 0; j <= m; j++) {
            for (int k = 0; k <= n; k++) {
                if (j < v[i][0] || k < v[i][1]) f[i][j][k] = f[i - 1][j][k];
                else {
                    f[i][j][k] = max(f[i - 1][j][k], f[i - 1][j - v[i][0]][k - v[i][1]] + 1);
                    // cout << f[i-1][j][k]<<" " <<f[i-1][j-v[i][0]][k-v[i][1]] << endl;
                }
                //  cout <<i<< " "<< j<<" " <<k<< " "<<f[i][j][k] << endl;
            }
        }
    }
    //cout << f[k][m][n] << endl;
    printf("%d", f[k][m][n]);
    return 0;
}

Mapleleave  •  3年前

请先登录,才能进行评论