Pagini recente » Cod sursa (job #451622) | Cod sursa (job #2425060) | Cod sursa (job #688425) | Cod sursa (job #3223213) | Cod sursa (job #7684)
Cod sursa(job #7684)
//100p
#include <stdio.h>
#include <algorithm>
#include <string.h>
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define NMAX 1001
using namespace std;
int A[NMAX][18], V[NMAX];
int i, j, N, M, R, C, ii, S, Sum, cnt, K, Max, sc, aux;
inline int bit_p(int b, int poz)
{
if (b & 1<<poz) return 1;
return 0;
}
int main()
{
freopen("elimin.in", "r", stdin);
freopen("elimin.out", "w", stdout);
scanf("%d %d %d %d", &N, &M, &R, &C);
if (N >= M)
{
for (i = 0; i < N; i++)
for (j = 0; j < M; j++) scanf("%d", &A[i][j]);
}
else
{
for (i = 0; i < N; i++)
for (j = 0; j < M; j++) scanf("%d", &A[j][i]);
aux = N; N = M; M = aux;
aux = R; R = C; C = aux;
}
for (i = 0; i < (1 << M); i++)
{
cnt = 0;
for (j = 0; j < M; j++) if (bit_p(i, j)) cnt++;
if (cnt == C)
{
S = K = sc = 0;
memset(V, 0, sizeof(V));
for (ii = 0; ii < N; ii++)
{
Sum = 0;
for (j = 0; j < M; j++)
if ( bit_p(i, j) == 0 ) Sum += A[ii][j];
V[++K] = Sum;
S += Sum;
}
sort(V+1, V+K+1);
for (ii = 1; ii <= R; ii++) sc += V[ii];
Max = MAX(Max, S - sc);
}
}
printf("%d\n", Max);
return 0;
}