Cod sursa(job #878814)

Utilizator avramavram andrei marius avram Data 14 februarie 2013 19:21:50
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include<fstream>
#include<cstdio>
 
using namespace std;
 
const int MaxN = 20;
 
const char InFile[] = "flip.in";
const char OutFile[] = "flip.out";
 
int N,M,F[MaxN][MaxN],Smax;
 
int main()
{
    ifstream fin( InFile );
    ofstream fout( OutFile );
    fin >> N >> M;
    int i,j,l,s,t;
    for( i = 0 ; i < N ; ++i )
        for( j = 0 ; j < M ; ++j )
            fin >> F[i][j];
    
    for( i = 0 ; i < (1 << M) ; ++i )
        {
            s = 0;
            for( l = 0 ; l < N ; ++l )
                {
                    t = 0;
                    for( j = 0 ; j < M ; ++j )
                        if( i & (1<<j) )
                            t = t - F[l][j]; 
                            else
                            t = t + F[l][j]; 
                    if( t > 0 )
                        s = s + t;
                        else
                        s = s - t;
                         
                }
            if( s > Smax )
                Smax = s;
        }
    fout << Smax << '\n';
    fin.close();
    fout.close();
    return 0;
}