Cod sursa(job #2236379)
| Utilizator | Data | 29 august 2018 12:48:48 | |
|---|---|---|---|
| Problema | Jocul Flip | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.71 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("flip.in");
ofstream g("flip.out");
int main()
{
int N,M,A[16][16];
f>>N>>M;
int s0=0;
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
{
f>>A[i][j];
s0+=A[i][j];
}
int smax=0;
for(int i=0;i<(1<<N);i++)
{
bitset<16> cX(i);
for(int j=0;j<(1<<M);j++)
{
bitset<16> cY(j);
int s=s0;
for(int p=0;p<N;p++)
for(int q=0;q<M;q++)
{
if(cX[p] ^ cY[q]) s-=2*A[p][q];
}
smax=max(smax,s);
}
}
g<<smax;
return 0;
}
