Pagini recente » Cod sursa (job #3360724) | Cod sursa (job #3360747) | Cod sursa (job #3360723) | Cod sursa (job #3360699) | Cod sursa (job #3360700)
#include <bits/stdc++.h>
using namespace std;
int N, M, R, C;
int main()
{
freopen("elimin.in", "r", stdin);
freopen("elimin.out", "w", stdout);
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N >> M >> R >> C;
int A[min(N, M)][max(N, M)];
for(int i = 0; i < N; i++)
{
for(int j = 0; j < M; j++)
{
if(N < M) cin >> A[i][j];
else cin >> A[j][i];
}
}
if(N > M) {swap(N, M); swap(R, C);}
int mx = 0, temp, SUM[M];
for(int mask = 0; mask < (1 << N); mask++)
{
if(__builtin_popcount(mask) != R) continue;
for(int j = 0; j < M; j++) SUM[j] = 0;
for(int i = 0; i < N; i++)
{
if(mask & (1 << i)) continue;
for(int j = 0; j < M; j++) SUM[j] += A[i][j];
}
sort(SUM, SUM + M);
temp = 0;
for(int j = C; j < M; j++) temp += SUM[j];
mx = max(temp, mx);
}
cout << mx << '\n';
return 0;
}