Cod sursa(job #2589680)

Utilizator cyg_vladioanBirsan Vlad cyg_vladioan Data 26 martie 2020 18:26:09
Problema Jocul Flip Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <cstdio>
#include <algorithm>
using namespace std;
const int NMAX = 16;
const int MMAX = 16;
const int DMAX = (1 << 16);
int a[NMAX + 5][MMAX + 5] , sp[DMAX + 5][MMAX + 5] , l[NMAX + 5] , c[MMAX + 5];
int main()
{
    freopen("flip.in" , "r" , stdin);
    freopen("flip.out" , "w" , stdout);
    int n , m , i , j , k , s , smax;
    scanf("%d%d" , &n , &m);
    for(i = 0 ; i < n ; i ++)
        for(j = 0 ; j < m ; j ++)
        {
            scanf("%d" , &a[i][j]);
            l[i] += a[i][j];
            c[j] += a[i][j];
        }
    for(j = 0 ; j < m ; j ++)
        for(i = 0 ; i < (1 << n) ; i ++)
            for(k = 0 ; k < n ; k ++)
                if((i & (1 << k)) != 0)
                    sp[i][j] += a[k][j];
    smax = 0;
    for(i = 0 ; i < (1 << n) ; i ++)
    {
        s = 0;
        for(j = 0 ; j < n ; j ++)
            if((i & (1 << j)) != 0)
                s -= l[j];
        for(j = 0 ; j < m ; j ++)
            s = max(s + c[j] - sp[i][j] , s - c[j] + 3 * sp[i][j]);
        smax = max(s , smax);
    }
    printf("%d\n" , smax);
    return 0;
}