Pagini recente » Cod sursa (job #713385) | Cod sursa (job #1276448) | Cod sursa (job #895750) | Cod sursa (job #646984) | Cod sursa (job #3221645)
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define lsb(x) (x & (-x))
#define YES { fout << "DA" << endl; return; }
#define NO { fout << "NU" << endl; return; }
using ll = long long;
using pii = std::pair<int, int>;
const int NMAX = 73e2;
using namespace std;
ifstream fin ("elimin.in");
ofstream fout ("elimin.out");
int n, m, r, c, splin[NMAX + 5], spcol[NMAX + 5], copie[NMAX + 5], sum = 0, ans = INT_MIN;
signed main() {
fin >> n >> m >> r >> c;
int mat[n + 5][m + 5];
memset(mat, 0, sizeof(mat));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (n <= m)
fin >> mat[i][j];
else
fin >> mat[j][i];
}
}
if (n > m)
swap(n, m), swap(r, c);
for (int i = 0 ; i < n; ++i)
for(int j = 0; j < m; j++)
splin[i] += mat[i][j], spcol[j] += mat[i][j], sum += mat[i][j];
for (int i = 0; i < (1 << n); i++) {
if (__builtin_popcount(i) == r) {
int elim = 0;
std::copy(begin(spcol), end(spcol), begin(copie));
for (int lin = 0; lin < n; lin++) {
if (i & (1 << lin)) {
for (int j = 0; j < m; j++)
copie[j] -= mat[lin][j];
elim += splin[lin];
}
}
sort(copie, copie + n);
for (int j = 0; j < c; j++)
elim += copie[j];
ans = max(ans, sum - elim);
}
}
fout << ans;
return 0;
}