Pagini recente » Cod sursa (job #546976) | Cod sursa (job #364971) | Cod sursa (job #1427097) | Cod sursa (job #1523265) | Cod sursa (job #1008575)
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("elimin.in");
ofstream g("elimin.out");
int N, M, R, C, maxsum;
vector<int> sum, aux;
vector<vector<int> > mat;
int main() {
int i, j, k, s, nrb;
f >> N >> M >> R >> C;
mat.resize(N+1, vector<int>(M+1));
sum.resize(M+1, 0);
aux.resize(M+1, 0);
for(i=1; i<=N; ++i)
for(j=1; j<=M; ++j)
if(N > M)
f >> mat[j][i];
else
f >> mat[i][j];
if(N > M) {
swap(N, M);
swap(R, C);
}
for(i=1; i<=N; ++i)
for(j=1; j<=M; ++j)
sum[j] += mat[i][j];
for(i=0; i<(1<<N); ++i) {
nrb = 0;
for(j=0; (1<<j)<=i; ++j)
if((1<<j) & i)
++nrb;
if(nrb != R)
continue;
copy(sum.begin(), sum.end(), aux.begin());
for(j=0; (1<<j)<=i; ++j)
if((1<<j) & i)
for(k=1; k<=M; ++k)
aux[k] -= mat[j+1][k];
nth_element(aux.begin(), aux.begin()+C, aux.end());
s = 0;
for(j=C+1; j<=M; ++j)
s += aux[j];
maxsum = max(maxsum, s);
}
g << maxsum;
f.close();
g.close();
return 0;
}