Pagini recente » Cod sursa (job #1013908) | Cod sursa (job #2624454) | Cod sursa (job #2908126) | Cod sursa (job #1043582) | Cod sursa (job #1992208)
#include <bits/stdc++.h>
using namespace std;
const int N = 4005;
int i, j, mask, n, m, r, c, a[N][N], rs, sum;
int main() {
ifstream cin("elimin.in");
ofstream cout("elimin.out");
ios_base::sync_with_stdio(0);
cin >> n >> m >> r >> c;
if(n < m) {
for(i = 0; i < n; ++i)
for(j = 0; j < m; ++j)
cin >> a[i][j];
} else {
for(j = 0; j < m; ++j)
for(i = n - 1; i >= 0; --i)
cin >> a[i][j];
swap(n, m);
}
for(mask = 0; mask < (1 << n); ++mask) {
if(__builtin_popcount(mask) != r) continue;
vector<int> v(m, 0);
for(i = 0; i < n; ++i) {
if(mask & (1 << i)) continue;
for(j = 0; j < m; ++j) v[j] += a[i][j];
}
sort(v.begin(), v.end());
for(sum = 0, i = c; i < m; ++i) sum += v[i];
rs = max(rs, sum);
}
cout << rs << '\n';
return 0;
}