Pagini recente » Cod sursa (job #2261610) | Cod sursa (job #2973466) | Cod sursa (job #2132140) | Cod sursa (job #1166072) | Cod sursa (job #978771)
Cod sursa(job #978771)
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
int n, m, **matrix;
unsigned short nplace = 0, mplace = 0, aux;
short retv(unsigned short a, int b)
{
aux = a>>b;
if(aux %2 == 0) return 1;
else return -1;
}
int sum()
{
int j, s=0;
for(int i = 0; i<n; i ++)
for(j = 0; j< m; j++)
s += matrix[i][j]*retv(nplace, i)* retv(mplace, j);
return s;
}
int main()
{
int i, j;
ifstream* mystream;
mystream = new ifstream("flip.in");
*mystream>>n;
*mystream >> m;
//create matrix
matrix = new int*[n];
for(i = 0; i<n; i++)
matrix[i] = new int[m];
//read matrix v. daca nu incurci lin cu col
for(i = 0; i<n; i++)
for(j = 0; j<m; j++)
*mystream>> matrix[i][j];
mystream->close();
int mysum, csum = 0;
int maxn = pow(2, n), maxm = pow(2, m);
for(nplace = 0; nplace< maxn; nplace ++)
for(mplace = 0; mplace< maxm-1; mplace ++)
{
mysum = sum();
if (csum<mysum) csum = mysum;
}
ofstream stream("flip.out");
stream<<csum;stream.close();
return 0;
}