Pagini recente » Cod sursa (job #1266503) | Cod sursa (job #173497) | Borderou de evaluare (job #1036264) | Cod sursa (job #1609111) | Cod sursa (job #2159545)
#include<fstream>
using namespace std;
ifstream fin("flip.in");
ofstream fout("flip.out");
const int NMAX = 17;
int Stack[NMAX], grid[NMAX][NMAX];
int rowsCnt, colsCnt, maxSum;
inline void readData(){
fin >> rowsCnt >> colsCnt;
int row, col;
for(row = 1; row <= rowsCnt; ++row)
for(col = 1; col <= colsCnt; ++col)
fin >> grid[row][col];
}
inline void checkSum(){
int sum = 0, row, col, rowSum;
for(row = 1; row <= rowsCnt; ++row){
rowSum = 0;
for(col = 1; col <= colsCnt; ++col)
rowSum += grid[row][col] * Stack[col];
if(rowSum < 0)
rowSum *= -1;
sum += rowSum;
}
maxSum = max(maxSum, sum);
}
void BKT(int StackLvl){
if(StackLvl > colsCnt)
checkSum();
else{
Stack[StackLvl] = 1;
BKT(StackLvl + 1);
Stack[StackLvl] = -1;
BKT(StackLvl + 1);
}
}
int main(){
readData();
BKT(1);
fout << maxSum;
}