Cod sursa(job #1882060)

Utilizator nick12nicolae mihalache nick12 Data 16 februarie 2017 22:11:37
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;
    int n,m,max1;
    int l[16];
    int t[16][16];
    vector <bool> v(17,0);
int main()
{

    freopen("flip.in","r",stdin);
    freopen("flip.out","w",stdout);

    int  i,j,g = 0,s,s1;
    cin >> n >> m;
    for (i = 0;i<n;i++)
        for (j =0;j<m;j++)
    {
       // cout << i<<endl;
        cin >> t[i][j];
        l[i]+=t[i][j];
    }
    while (!g)
    {

       s=0;
        for(j=0; j<m; j++)
        {
            s1=0;
            for(i=0; i<n; i++)
                if(v[i]==1) s1-=t[i][j];
                else s1+=t[i][j];
            if(s1<0) s1=-s1;
            s+=s1;
        }
        if(s>max1) max1=s;
        for(i=n-1; i>=0 && v[i]==1; i--) v[i]=0;
        if(i>=0) v[i]=1;
        else g=1;
    }
    cout << max1;
    return 0;
}