Topic links
Give a number of 0 1, flip one will make him and the left and right sides of the change, the minimum number of times can become full 0.
Template title.
#include <iostream>#include<vector>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<map>#include<Set>#include<string>#include<queue>#include<stack>#include<bitset>using namespacestd;#definePB (x) push_back (x)#definell Long Long#defineMK (x, y) make_pair (x, y)#defineLson L, M, rt<<1#defineMem (a) memset (a, 0, sizeof (a))#defineRson m+1, R, rt<<1|1#defineMem1 (a) memset (a,-1, sizeof (a))#defineMEM2 (a) memset (a, 0x3f, sizeof (a))#defineRep (i, N, a) for (int i = A; i<n; i++)#defineFi first#defineSe Secondtypedef pair<int,int>PLL;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-8;Const intMoD = 1e9+7;Const intINF =1061109567;Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} };inta[ -][ -], ans[ -], x[ -];intN, l[ -], free_x[ -];intGaussintEquint var){ intI,j,k, max_r, col =0, temp, free_index, num =0; for(intI=0; i<=var; i++) {X[i]=0; Free_x[i]=0; } for(k =0; k < equ && Col <var; k++,col++) {Max_r=K; for(i=k+1; i<equ;i++) { if(ABS (A[i][col]) >abs (A[max_r][col]) max_r=i; } if(max_r!=k) { for(j=k;j<var+1; j + +) Swap (a[k][j],a[max_r][j]); } if(a[k][col]==0) {k--; Free_x[num++]=Col; Continue; } for(i=k+1; i<equ;i++) { if(a[i][col]!=0) { for(j=col;j<var+1; j + +) {A[i][j]^=A[k][j]; } } } } for(i = k; i < equ; i++) { if(A[i][col]! =0)return-1; } intStat =1<< (var-k); intres =inf; for(i=0; i<stat;i++) { intCnt=0; intindex=i; for(j=0;j<var-k;j++) {X[free_x[j]]= (index&1); if(X[free_x[j]]) cnt++; Index>>=1; } for(j=k-1; j>=0; j--) { inttmp=a[j][var]; intt=0; while(a[j][t]==0) t++; for(intl=t+1;l<var; l++) if(A[j][l]) tmp^=X[l]; X[t]=tmp; if(X[t]) cnt++; } if(cnt<res) res=CNT; } returnRes;}intMain () { for(inti =0; i< -; i++) {scanf ("%d", &a[i][ -]); } for(inti =0; i< -; i++) { if(i) {a[i][i-1] =1; } if(i!= +) A[i][i+1] =1; A[i][i]=1; } intAns = Gauss ( -, -); cout<<ans<<Endl; return 0;}
POJ 3185 The water bowls Gaussian elimination variable element