Pagini recente » Cod sursa (job #3281882) | Cod sursa (job #3132337) | Cod sursa (job #1367843) | Cod sursa (job #2741260) | Cod sursa (job #2325880)
#include <fstream>
#define INPUT_PATH ""
#define OUTPUT_PATH ""
void algorithm();
int main()
{
algorithm();
return 0;
}
using namespace std;
namespace
{
const int maxRow = 16;
const int maxCol = 16;
int rows = 0;
int cols = 0;
int matrix[maxRow][maxCol];
int colSign[maxCol] = { 1 };
int solution = 0;
void solve(int colNr)
{
if (colNr == cols)
{
int sum = 0;
for (int row = 0; row < rows; ++row)
{
int sumRow = 0;
for (int col = 0; col < cols; ++col)
sumRow += colSign[col]*matrix[row][col];
sum += sumRow > 0 ? sumRow : -sumRow;
}
solution = sum > solution ? sum : solution;
return;
}
colSign[colNr] = 1; solve(colNr + 1);
colSign[colNr] = -1; solve(colNr + 1);
}
}
////////////////////////////////////////////////////////////////////////////////
void algorithm()
{
ifstream inputFile(INPUT_PATH "flip.in");
ofstream outputFile(OUTPUT_PATH "flip.out");
inputFile >> rows >> cols;
for (int row = 0; row < rows; ++row)
for (int col = 0; col < cols; ++col)
inputFile >> matrix[row][col];
solve(0);
outputFile << solution;
inputFile.close();
outputFile.close();
}