全WA, 求调

P2704 [NOI2001] 炮兵阵地

MagicLyney_06 @ 2023-10-10 21:08:01

全WA了, 不知道哪里有问题, 大佬求调

//
// Created by lndff on 2023/10/8.
//
#include <bits/stdc++.h>

#define MAXN 110
#define MAXM 15

int a[MAXN][MAXM];
using namespace std;
unordered_map<int, int>hax;
int n, m;
int f[MAXN][(1 << 11) - 1];
inline bool isch(char s){
    if (s >= 'A' && s <= 'Z') return 1;
    return 0;
}

inline bool check(int x){
    if (x & (x << 1)) return false;
    if (x & (x << 2)) return false;
    if (x & (x >> 1)) return false;
    if (x & (x >> 2)) return false;
    return true;
}

int lowbit(int x){
    return x & (-x);
}
inline bool check2(int x, int line){
    while (x){
        if (!a[line][m-  hax[lowbit(x)]]) return false;
        x -= lowbit(x);
    }
    return true;
}

inline bool check3(int x, int y){
    if (x & y) return false;
    return true;
}
vector <int> law;

inline int count(int x){
    int ans = 0;
    while (x){
        x -= lowbit(x);
        ++ans;
    }
    return ans;
}
int main(){
    for (int i = 0; i <= 10; i++){
        hax.insert(make_pair(1 << i, i + 1));
    }
    scanf("%d%d", &n, &m);
    char s;
    for (int i = 1; i <= n; i++){
        for (int p = 1; p <= m; p++){
            while (!isch(s = getchar()));
            if (s == 'P') a[i][p] = 1;
            else a[i][p] = 0;
        }
    }
    int limit = (1 << m) - 1;
    for (int i = 1; i <= limit; i++){
        if (check(i)) law.push_back(i);
    }
    for (auto i : law){
        if (check2(i, 1)){
            f[1][i] = count(i);
//            cout << i;
        }
    }
//    cout << check
    for (int i = 2; i <= 2; i++){
        for (auto j : law){
            if (check2(j, i)){
                int cj = count(j);
                for (auto p : law){
                    if (check2(p, i - 1)){
                        if (check3(p, j)){
                            f[i][j] = max(f[i][j], count(p) + cj);
                        }
                    }
                }
            }
        }
    }
    for (int i = 3; i <= n; i++){
        for (auto j : law){
            if (check2(j, i)){
                int cj = count(j);
                for (auto p : law){
                    if (check2(p, i - 1)){
                        if (check3(p, j)){
                            int cp = count(p);
//                            f[i][j] += f[i - 1][p];
                            for (auto k : law){
                                if (check2(k, i - 2)){
                                    if (check3(p, k) && check3(k, j))
                                    {
                                        f[i][j] = max(f[i][j], f[i - 2][k] + cp + cj);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for (auto j : law){
        ans = max(ans, f[n][j]);
    }
    printf("%d", ans);
}
/*
30 7
PPPPHHP
PPPHPHP
PPPHPPP
HPPHHPH
PPPHHHP
PHPPPPH
HHPPPPP
PPPHHPP
PPHHPPP
HHHPPHP
HPHPHHP
PPPHPPH
PHPPPPP
PHPPPHP
HHPHHPH
PHHPPHP
PHPHPPP
PHPHPPH
PPPPPPP
PPPHPHP
PPHPPPH
PPPPHPP
PPPHHPP
PPHPPPP
PPHHPPP
HPHPPHP
PHPHHPP
PPHHHHH
PHHHPPH
PHPPHPH

56
*/

/*
 * 
 */

|