Pagini recente » Cod sursa (job #999571) | Cod sursa (job #1108852) | Cod sursa (job #258159) | Cod sursa (job #1088889) | Cod sursa (job #1014505)
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#define kNMAX 700
int Mat[kNMAX][kNMAX], suma[kNMAX];
int nrLinii, nrColoane, xColoane, xLinii, sumaInitiala, sumaMax;
std::fstream in, out;
void citire(){
in >> nrLinii >> nrColoane >> xLinii >> xColoane;
if (nrLinii <= nrColoane){
for(int i = 1; i <= nrLinii; i++)
for(int j = 1; j <= nrColoane; j++){
in >> Mat[i][j];
}
}else{
for(int i = 1; i <= nrLinii; i++)
for(int j = 1; j <= nrColoane; j++){
in >> Mat[j][i];
}
std::swap(nrLinii, nrColoane);
std::swap(xColoane, xLinii);
}
return;
}
int main(){
in.open("elimin.in", std::ios::in);
out.open("elimin.out", std::ios::out);
citire();
for(int i = 1; i < (1 << nrLinii); i++){
int nr1 = 0;
for(int j = 0; j < nrColoane; j++){
if (1 << j & i) nr1++;
}
if (nr1 != nrColoane - xLinii) continue;
std::fill(suma, suma + nrColoane + 1, 0);
for(int j = 1; j < (1 << nrLinii); j++){
if ((1 << (j - 1)) & i){
for(int c = 1; c <= nrColoane; c++)
suma[c] += Mat[j][c];
}
}
std::sort(suma + 1, suma + nrLinii + 1);
int aux = 0;
for(int i = xColoane + 1; i <= nrLinii; i++){
aux += suma[i];
}
sumaMax = std::max(aux, sumaMax);
}
std::cout << "Suma: " << sumaMax << std::endl;
out << sumaMax;
in.close();
out.close();
return 0;
}