有没有用高斯消元做的

P2040 打开所有的灯

orz
by 小粉兔 @ 2018-04-23 22:52:36


高斯消元裸题啊emmmmm
by strangers @ 2018-04-23 23:07:26


你去出个9*9的吧
by 142857cs @ 2018-10-16 15:51:37


```cpp #include<cstdio> #include<algorithm> #include<cstdio> #include<cmath> const int N=100; using namespace std; int a[N][N],ans[N],Max=1000000; void _swap(int x,int y) { if(x==y) return; for(int i=1;i<=10;i++) swap(a[x][i],a[y][i]); } void dfs(int now,int tot) { if(tot>=Max) return; if(!now) { Max=min(Max,tot); return ; } if(a[now][now]) { ans[now]=a[now][10]; for(int i=now+1;i<=9;i++) if(a[now][i]) ans[now]^=ans[i]; dfs(now-1,tot+(ans[now]!=0)); }else{ ans[now]=1;dfs(now-1,tot+1); ans[now]=0;dfs(now-1,tot); } } void Gauss() { for(int i=1;i<=9;i++) { int l=i; while(l<=9&&!a[l][i]) l++; if(l>9) continue; _swap(i,l); for(int j=1;j<=9;j++) if(i!=j&&a[j][i]) for(int k=1;k<=10;k++) a[j][k]^=a[i][k]; } } int main() { for(int i=1;i<=9;i++) scanf("%d",&a[i][10]),a[i][10]^=1; a[1][2]=a[1][4]=a[2][1]=a[2][3]=a[2][5]=a[3][2]=a[3][6]=a[4][1]= a[4][5]=a[4][7]=a[5][2]=a[5][4]=a[5][6]=a[5][8]=a[6][5]=a[6][3]= a[6][9]=a[7][4]=a[7][8]=a[8][7]=a[8][5]=a[8][9]=a[9][8]=a[9][6]=1; for(int i=1;i<=9;i++) a[i][i]=1; Gauss(); dfs(9,0); printf("%d\n",Max); return 0; } ``` 高斯消元(逃)
by Ink_Cat @ 2019-07-18 17:59:18


不是20*20比较正常吗
by loveJY @ 2019-10-01 11:32:04


hdu有高消版的啊
by yuzhechuan @ 2019-10-05 21:56:47


|