Cod sursa(job #1114214)

Utilizator Cristian1997Vintur Cristian Cristian1997 Data 21 februarie 2014 13:45:11
Problema Jocul Flip Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
using namespace std;
#include <fstream>
#include <vector>
#include <algorithm>
ifstream fin("flip.in");
ofstream fout("flip.out");

int m, n, max1=0; // n linii    m coloane
int l[16];
int t[16][16];
vector <bool> v(16, 0);


int main()
{
    int i, j, k, gata=0, s, s1;
    fin>>m>>n;
    for(i=0; i<n; i++)
        for(j=0; j<m; j++)
            {fin>>t[i][j]; l[i]+=t[i][j];}
    while(!gata)
    {
        s=0;
        for(j=0; j<m; j++)
        {   //calculam fiecare coloana
            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 gata=1;
    }
    fout<<max1;
    return 0;
}