90分求助

P2704 [NOI2001] 炮兵阵地

7FA5 @ 2022-10-12 13:36:54

#include <bits/stdc++.h>
using namespace std;
const int N = 105, M = 15, K = 1029;
int n, m, k;
int p[N];
int pc[K];
int read_int() {
    int a = 0;
    char c;
    int f = 1;
    do {
        c = getchar();
    } while(c == ' ' || c == '\n');
    if(c == '-') {
        f = -1;
        c = getchar();
    }
    while(c != ' ' && c != '\n') {
        a = (a << 3) + (a << 1) + c - '0';
        c = getchar();
    }
    return a * f;
}
char read_char() {
    char c;
    do {
        c = getchar();
    } while(c == ' ' || c == '\n');
    return c;
}
bool check1(int x) {
    return !((x << 1) & x) && !((x << 2) & x);
}
bool check2(int x, int y) {
    return !(x & y);
}
int dp[N][K][K], ans;
int main() {
    n = read_int();
    m = read_int();
    k = (1 << m) - 1;
    for(int i = 1; i <= n; i++)
        for(int j = 0; j < m; j++) {
            char c = read_char();
            if(c == 'H')
                p[i] = p[i] + (1 << j);
        }
    for(int nw = 0; nw <= k; nw++) {
        pc[nw] = pc[nw >> 1] + (nw & 1);
        if((nw & p[1]) == 0 && check1(nw)) {
            dp[1][nw][0] = pc[nw];
            ans = max(ans, dp[1][nw][0]);
        }
    }
    for(int i = 2; i <= n; i++)
        for(int nw = 0; nw <= k; nw++)
            if((nw & p[i]) == 0 && check1(nw))
                for(int fr = 0; fr <= k; fr++)
                    if(check2(nw, fr))
                        for(int frfr = 0; frfr <= k; frfr++)
                            if(check2(nw, frfr) && check2(fr, frfr)) {
                                dp[i][nw][fr] = max(dp[i][nw][fr], dp[i - 1][fr][frfr] + pc[nw]);
                                ans = max(ans, dp[i][nw][fr]);
                            }
    printf("%d", ans);
    return 0;
}

by 7FA5 @ 2022-10-12 13:37:12

第一个点WA了


by seanlsy @ 2022-10-13 13:41:42

getchar() 出锅了吧


|