Cod sursa(job #3352596)

Utilizator gabriel47291Vaduva Gabriel - Teodor gabriel47291 Data 29 aprilie 2026 11:09:20
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
using namespace std;
int a[16][16], c[16][16];
int n, m, i, j, b, k, slin, scurent, smax;
int main () {
    ifstream fin ("flip.in");
    ofstream fout("flip.out");

    fin>>n>>m;
    for (i=0;i<n;i++)
        for (j=0;j<m;j++)
            fin>>a[i][j];

    
    for (k=0;k<(1<<m);k++) 
    {
        for (i=0;i<n;i++)
            for (j=0;j<m;j++)
                c[i][j] = a[i][j];
        for (b=0;b<m;b++) {
            if ((k>>b) & 1) {
                   for (i=0;i<n;i++)
                    c[i][b] = -c[i][b];
            }
        }

       
        scurent = 0;
        for (i=0;i<n;i++) {
            slin = 0;
            for (j=0;j<m;j++)
                slin += c[i][j];
            if (slin < 0)
                scurent -= slin;
            else
                scurent += slin;
        }

        if (scurent > smax)
            smax = scurent;

       
    }
    fout<<smax;
}