Cod sursa(job #939974)

Utilizator alecsandrualex cuturela alecsandru Data 15 aprilie 2013 11:34:27
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include<cstdio>
int n,m,v[20][20],rez,st[20];
void check()
{
    int i,j,stemp,smat;
    smat=0;
    for(i=1;i<=m;i++)
    {
        stemp=0;
        for(j=1;j<=n;j++)
            if(st[j]==1)
                stemp=stemp+v[j][i];
            else
                stemp=stemp-v[j][i];
        if(stemp>0)
            smat=smat+stemp;
        else
            smat=smat-stemp;
    }
    if(smat>rez)
        rez=smat;
}
void back(int k)
{
    int i;
    if(k==n+1)
        check();
    else
        for(i=0;i<2;i++)
        {
            st[k]=i;
            back(k+1);
        }
}
int main()
{
    int i,j;
    freopen("flip.in","r",stdin);
    freopen("flip.out","w",stdout);
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
        scanf("%d",&v[i][j]);
    back(1);
    printf("%d",rez);
    return 0;
}