# Codeforces663E. Binary Table

$n \leq 20,m \leq 100000$的01矩阵，可整行整列01翻转，问最少剩几个1.

 1 //#include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 //#include<math.h>
5 //#include<set>
6 //#include<queue>
7 //#include<bitset>
8 //#include<vector>
9 #include<algorithm>
10 #include<stdlib.h>
11 using namespace std;
12
13 #define LL long long
15 {
16     char c; int s=0,f=1; while ((c=getchar())<'0' || c>'9') (c=='-') && (f=-1);
17     do s=s*10+c-'0'; while ((c=getchar())>='0' && c<='9'); return s*f;
18 }
19
20 //Pay attention to '-' , LL and double of qread!!!!
21
22 int K,n;
23 #define maxn 1100011
24 int b[maxn],f[22][maxn];
25
26 int main()
27 {
29     {
30         char c;
31         for (int i=0;i<K;i++)
32             for (int j=1;j<=n;j++)
33             {
34                 while ((c=getchar())!='0' && c!='1');
35                 b[j]|=(c-'0')<<i;
36             }
37         for (int i=1;i<=n;i++) f[0][b[i]]++;
38     }
39     int T=1<<K,ans=0x3f3f3f3f;
40     for (int i=1;i<=K;i++)
41     {
42         for (int j=0;j<T;j++)
43         {
44             if (i>1) f[i][j]=(i-2-K)*f[i-2][j];
45             for (int k=0;k<K;k++) f[i][j]+=f[i-1][j^(1<<k)];
46             f[i][j]/=i;
47         }
48     }
49     for (int i=0;i<T;i++)
50     {
51         int tmp=0;
52         for (int j=0;j<=K;j++) tmp+=min(j,K-j)*f[j][i];
53         ans=min(ans,tmp);
54     }
55     printf("%d\n",ans);
56     return 0;
57 }
View Code

posted @ 2018-06-21 07:48  Blue233333  阅读(189)  评论(0编辑  收藏  举报