Cod sursa(job #3210215)

Utilizator ForitaroFurcuta Florin Foritaro Data 5 martie 2024 14:57:46
Problema Jocul Flip Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("flip.in");
ofstream g("flip.out");

int v[20][20], n = 1, m = 1, tot, sum_max, S = 0;
int op[40];


void Back(int k)
{
    if(k == tot + 1)
    {

        int Sc = 0;


        for(int i = 1; i <= n; i ++)
        {
            for(int j = 1; j <= m; j ++)
            {
                Sc = Sc + (op[i] * op[n + j] * v[i][j]);
            }

        }


        if(Sc > sum_max)
        {
            sum_max = Sc;
        }

    }
    else
    {
        for(int i = -1; i <= 1; i += 2)
        {
            op[k] = i;

            Back(k + 1);
        }
    }


}



int main()
{
    int i, j;

    f >> n >> m;

    tot = n + m;

    for(i = 1; i <= n; i ++)
    {
        for(j = 1; j <= m; j ++)
        {
            f >> v[i][j];

            S += v[i][j];
        }
    }


    sum_max = S / 2;

    Back(1);


    g << sum_max;

    return 0;
}