Cod sursa(job #3211390)

Utilizator apoputoaievladVlad Cristian Apoputoaie apoputoaievlad Data 9 martie 2024 11:15:44
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin("flip.in");
ofstream fout("flip.out");


int main()
{
    int b[20][20],n,m;
    int i,j,stot,s,a[20]={0},smax=INT_MIN;
    fin>>n>>m;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
        fin>>b[i][j];
    while(a[0]==0)
    {
        stot=0;
        for(i=1;i<=n;i++)
        {
            s=0;
            for(j=1;j<=m;j++)
            {
                if(a[j]==0)
                    s+=b[i][j];
                else s-=b[i][j];
            }
            stot+=abs(s);
        }
        smax=max(smax,stot);
        j=m;
        while(a[j]==1)
        {
            a[j]=0;
            j--;
        }
        a[j]=1;
    }
    fout<<smax;
    return 0;
}