1. 程式人生 > >luoguP3185 [HNOI2007]分裂遊戲 列舉 + 博弈論

luoguP3185 [HNOI2007]分裂遊戲 列舉 + 博弈論


每個位置的瓶子中的每個石子是一個獨立的遊戲

只要計算出他們的\(sg\)值即可

至於方案數,反正不多\(n^3\)暴力列舉即可

反正怎麼暴力都能過啊

複雜度\(O(Tn^3)\)


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define ri register int
#define rep(io, st, ed) for(ri io = st; io <= ed; io ++)
#define drep(io, ed, st) for(ri io = ed; io >= st; io --)

#define gc getchar
inline int read() {
    int p = 0, w = 1; char c = gc();
    while(c < '0' || c > '9') { if(c == '-') w = -1; c = gc(); }
    while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();
    return p * w;
}

int n, sg[25], mex[105];

inline void get_sg() {
    sg[n] = 0;
    drep(i, n - 1, 1) {
        memset(mex, 0, sizeof(mex));
        rep(j, i + 1, n) rep(k, j, n)
        mex[sg[j] ^ sg[k]] = 1;
        rep(j, 0, 100)
        if(!mex[j]) { sg[i] = j; break; }
    }
}

int main() {
    int T = read();
    while(T --) {
        n = read(); get_sg();
        int SG = 0;
        rep(i, 1, n) SG ^= (read() & 1) * sg[i];
        if(!SG) {
            printf("-1 -1 -1\n");
            printf("0\n"); continue;
        }
        int ans = 0, flag = 0;
        rep(i, 1, n) rep(j, i + 1, n) rep(k, j, n)
            if((SG ^ sg[i] ^ sg[j] ^ sg[k]) == 0) {
                if(!flag) { printf("%d %d %d\n", i - 1, j - 1, k - 1); flag = 1; }
                ans ++;
            }
        printf("%d\n", ans);
    }
    return 0;
}