Cod sursa(job #1582166)

Utilizator EuEricCiordel Rromeo EuEric Data 27 ianuarie 2016 18:25:56
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include<fstream>
using namespace std;
int a[20][20];
int main()
{
    ifstream cin("flip.in");
    ofstream cout("flip.out");
    int n,nr,max,m;
    cin>>n>>m;
    nr=1<<n;
   int sact,smax=0,stot;
   for(int i=1;i<=n;++i)
   for(int j=1;j<=m;++j)
   {
       cin>>a[i][j];
       smax+=a[i][j];
   }
   nr=1<<m;
   for(int i=1;i<nr;++i)
   {
       int stot=0;
       for(int j=1;j<=n;++j)
       {
           int sact=0,sact2=0;
           for(int k=1;k<=m;++k)
           {
                if(i&(1<<(k-1))){
                sact-=a[j][k];
                sact2+=a[j][k];
                }
                else{
                sact+=a[j][k];
                sact2-=a[j][k];
                }
           }
           if(sact>sact2)
           stot=stot+sact;
           else
           stot=stot+sact2;
       }
       if(stot>smax)
        smax=stot;
   }
   cout<<smax;
}