Cod sursa(job #2682987)

Utilizator rotarmirRotar Raul rotarmir Data 10 decembrie 2020 09:13:57
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fi("flip.in");
ofstream fo("flip.out");
int N,M;
int mat[17][17];
int sum_max;
int c[17];
void backy(int k)
{
    if(k==M+1)
    {
        int sum_mat=0;
        for(int i=1;i<=N;i++)
        {
            int sum_col=0;
            for(int j=1;j<=M;j++)
            {
                sum_col=sum_col+(mat[i][j]*c[j]);
            }
            if(sum_col<0)
                sum_col=-sum_col;
            sum_mat+=sum_col;
        }
        if(sum_mat>sum_max)
            sum_max=sum_mat;
    }else
    {
        c[k]=1;
        backy(k+1);
        c[k]=-1;
        backy(k+1);
    }
}
int main()
{
    fi>>N>>M;
    for(int i=1;i<=N;i++)
        for(int j=1;j<=M;j++)
            fi>>mat[i][j];
    backy(1);
    fo<<sum_max;
    return 0;
}