Pagini recente » Cod sursa (job #1431291) | Cod sursa (job #1638673) | Cod sursa (job #81305) | Cod sursa (job #390759) | Cod sursa (job #27664)
Cod sursa(job #27664)
#include<fstream.h>
ifstream f("flip.in");
ofstream g("flip.out");
float t[20][20];
int m,n,st[20];
double s=-50000;
void citire()
{
int i,j;
f>>m>>n;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
f>>t[i][j];
f.close();
}
void flipuieste()
{
int i,j;
double sn=0,sp=0,stot=0;
stot=0;
for(i=1;i<=m;i++)
{
sn=sp=0;
for(j=1;j<=n;j++)
if((t[i][j]*st[j])<0)sn+=-t[i][j]*st[j];
else sp+=t[i][j]*st[j];
if(sp<sn)stot+=sn-sp;
else stot+=sp-sn;
}
if(stot>s)s=stot;
}
void back(int k)
{
if(k>n)flipuieste();
else
for(int i=1;i>=-1;i-=2)
{
st[k]=i;
back(k+1);
}
}
int main()
{
citire();
back(1);
g<<s;
g.close();
return 0;
}