求助subtask1WA5个点

P2704 [NOI2001] 炮兵阵地

Fat_Fish @ 2022-02-12 15:03:45

#include<bits/stdc++.h>
using namespace std;
const int maxn = 117, maxm = 11;
int n, m, ans, state[maxn], f[2][1 << maxm][1 << maxm]; //last now
inline int calc(int x) {
    int cnt = 0;
    while (x)++cnt, x &= x - 1;
    return cnt;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        int buff = 1 << (m - 1);
        for (int j = 1; j <= m; ++j) {
            char c;
            cin >> c;
            state[i] += (c == 'H') * buff;
            buff >>= 1;
        }
    }
    for (int i = 0; i < (1 << m); ++i) {
        if ((i & state[1]) || (i & (i >> 1)) || (i & (i >> 2)) || (i & (i << 1)) || (i & (i << 2)))
            continue;
        f[1 & 1][0][i] = calc(i);
        for (int j = 0; j < (1 << m); ++j) {
            if ((i & j) || (j & state[2]) || (j & (j >> 1)) || (j & (j >> 2)) || (j & (j << 1)) || (j & (j << 2)))
                continue;
            f[2 & 1][i][j] = f[1 & 1][0][i] + calc(j);
        }
    }
    for (int l = 3; l <= n; ++l) {
        for (int i = 0; i < (1 << m); ++i) {
            if ((i & state[l - 2]) || (i & (i >> 1)) || (i & (i >> 2)) || (i & (i << 1)) || (i & (i << 2)))
                continue;
            for (int j = 0; j < (1 << m); ++j) {
                if ((i & j) || (j & state[l - 1]) || (j & (j >> 1)) || (j & (j >> 2)) || (j & (j << 1)) || (j & (j << 2)))
                    continue;
                for (int k = 0; k < (1 << m); ++k) {
                    if ((i & k) || (j & k) || (k & state[l]) || (k & (k >> 1)) || (k & (k >> 2)) || (k & (k << 1)) || (k & (k << 2)))
                        continue;
                    f[l & 1][j][k] = f[l - 1 & 1][i][j] + calc(k);
                }
            }
        }
    }
    for (int i = 0; i < (1 << m); ++i)
        for (int j = 0; j < (1 << m); ++j)
            ans = max(ans, f[n & 1][i][j]);
    cout << ans << '\n';
    return 0;
}

RECORD


by Fat_Fish @ 2022-02-12 15:25:22

正常缩进


by cookiebus @ 2022-02-12 16:19:37

不取min么,

f[l & 1][j][k] = f[l - 1 & 1][i][j] + calc(k);

本题似乎是求最小值?


by Fat_Fish @ 2022-02-13 08:28:01

谢谢,题目要求取最大值,过了


|