Pagini recente » Cod sursa (job #2392684) | Cod sursa (job #852131) | Cod sursa (job #2936864) | Cod sursa (job #1796264) | Cod sursa (job #2295751)
#include <bits/stdc++.h>
using namespace std;
ifstream in("elimin.in");
ofstream out("elimin.out");
int m, n, r, c, table[1050][1050], ans = -1e9;
bool col[15];
void solve() {
vector< int > sums;
for(int i = 1; i <= m; ++i) {
int tempSum = 0;
for(int j = 1; j <= n; ++j) {
if(!col[j]) {
tempSum += table[i][j];
}
}
sums.push_back(tempSum);
}
sort(sums.begin(), sums.end());
int currSum = 0;
for(int i = r; i < m; ++i) {
currSum += sums[i];
}
ans = max(ans, currSum);
}
void bkt(int colsDeleted) {
if(colsDeleted == c) {
solve();
return;
} else {
for(int i = 1; i <= n; ++i) {
if(!col[i]) {
col[i] = true;
bkt(colsDeleted + 1);
col[i] = false;
}
}
}
}
int main() {
ios::sync_with_stdio(false); in.tie(0); out.tie(0);
in >> m >> n >> r >> c;
for(int i = 1; i <= m; ++i) {
for(int j = 1; j <= n; ++j) {
in >> table[i][j];
}
}
bkt(0);
out << ans << "\n";
in.close(); out.close();
return 0;
}