Cod sursa(job #2755228)

Utilizator EduardSubreduSubredu Eduard EduardSubredu Data 26 mai 2021 21:39:45
Problema Jocul Flip Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
#pragma warning(disable : 4996)
#include <iostream>
#include <fstream>
#include <cmath>
#include <string.h>
using namespace std;

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

int s_max = 0, n, m, a[20][20];
void suma(int b[][20], int i1, int j1)
{
    if(i1 < n) suma(a, i1 + 1, j1);
    if(j1 < m) suma(a, i1, j1 + 1);
    int s = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
            b[i][j] = a[i][j];
    }
    for (int j = 1; j <= m; j++)
        b[i1][j] *= -1;
    for (int i = 1; i <= n; i++)
        b[i][j1] *= -1;

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
            s += b[i][j];
    }
    if (s > s_max) s_max = s;
}

int main()
{
    f >> n >> m;
    for(int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            f >> a[i][j];
        }
    suma(a, 0, 0);
    g << s_max;
    return 0;
}