POJ - 3185 The Water Bowls
模型是个线性模2方程组。高斯消元的话可能解不唯一,要找独立变元。
但是不难看出,枚举左端点按下的状态,之后可以影响端点就只有一个变量了,根据端点递推了,然后检查。(写的时候想的是枚举左右端点
/********************************************************* * ------------------ * * author AbyssalFish * **********************************************************/ #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<queue> #include<vector> #include<stack> #include<vector> #include<map> #include<set> #include<algorithm> #include<cmath> #include<numeric> using namespace std; const int N = 20; int b[N]; //#define LOCAL int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif for(int i = 0; i < N; i++) scanf("%d",b+i); int best = N; for(int S = 4; S--;){ int x = S&1, y = S>>1; b[0] ^= x; b[1] ^= x; b[N-2] ^= y; b[N-1] ^= y; int v[N+3] = {}; int rv = 0, ans = x+y; for(int i = 0; i < N; i++){ if(b[i]^(rv^=v[i])){ if(i < N-2){ v[i+3] ^= 1; rv ^= 1; ans++; } else{ ans = best+1; break; } } } best = min(best,ans); b[0] ^= x; b[1] ^= x; b[N-2] ^= y; b[N-1] ^= y; } printf("%d\n", best); return 0; }