求调 QwQ
查看原帖
求调 QwQ
1036180
ChampionCyan楼主2025/8/1 11:24
#include <bits/stdc++.h>
using namespace std;
const int P = 1e6 + 1e3, MAXN = 2e6 + 2e3 + 5;
int dp[2][MAXN], l, r;
int main() {
    cin.tie(0) -> sync_with_stdio(0);
    int n;
    cin >> n;
    memset(dp, -0x3f, sizeof(0x3f));
    dp[0][P] = 0;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        int w = 0, v = 0;
        for (int j = 0; j < s.length(); j += 2)
            if (s[i] == 'c')
                w++;
            else
                v++;
        v -= w;
        l = min(l, l + v), r = max(r, r + v);
        for (int j = l; j <= r; j++)
            dp[i & 1][j + P] = max({dp[i & 1][j + P], dp[i & 1 ^ 1][j + P], dp[i & 1 ^ 1][j - v + P] + w});
    }
    printf("%d\n", dp[n & 1][P]);
    return 0;
}
2025/8/1 11:24
加载中...