Cod sursa(job #1222485)

Utilizator forever16Alex M forever16 Data 23 august 2014 13:38:16
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>

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

 int n, m,i,j, sol=0;
 int a[17][17], poz[17];

void joc() {
    int S=0;
    for (i=1; i<=n; i++) {
        int s=0;
    for (j=1; j<=m; j++)
        if (poz[j]) s+=a[i][j];
        else s-=a[i][j];
    if (s<0) s*=-1;
    S+=s; }
    if (sol<S) sol=S;  }

void fun(int x)
{
    if (x==m)
    {
    poz[x]=0;
    joc();
    poz[x]=1;
    joc(); }

    else
{
    poz[x]=0;
    fun(x+1);
    poz[x]=1;
    fun(x+1);
    }
}

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