Pagini recente » Rating Parasca Marius (NoWay) | Cod sursa (job #927176) | Cod sursa (job #2099065) | Cod sursa (job #906867) | Cod sursa (job #139201)
Cod sursa(job #139201)
#include <fstream.h>
ifstream f("flip.in");
ofstream g("flip.out");
long sol[20],n,m,p,k,mat[20][20],s,smax;
void citire();
long suma_mat();
int main(){
citire();
k=1;
while (k>0){
if (sol[k]>1) sol[--k]++;
else if (k<m) sol[++k]=0;
else if (k==m){s=suma_mat();if (s>smax) smax=s;sol[k]++;}
}
g<<smax;
f.close();
g.close();
return 0;
}
void citire(){
f>>n>>m;
int i,j;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
f>>mat[i][j];
}
long suma_mat(){
long j,s,st=0,semn;
for (int i=0;i<n;i++) {
s=0;
for (j=0;j<m;j++){
semn=(sol[j+1]==0?1:-1);
s+=semn*mat[i][j];
}
if (s<0) s*=(-1);
st+=s;
}
return st;
}