Pagini recente » Cod sursa (job #2201402) | Istoria paginii runda/simulare_clasa_9_oji | Cod sursa (job #2945765) | Cod sursa (job #1212928) | Cod sursa (job #1674656)
#include <fstream>
#include <algorithm>
#include <string.h>
#define sum first
#define poz second
using namespace std;
ifstream f("elimin.in");
ofstream g("elimin.out");
int n, m, l, c, x, v[20];
long long sumMax, newSum, s[7300], s_col[7300], sum;
short a[20][7300];
void aflu_solutie()
{
newSum = 0;
for(int j = 1; j <= m; ++j){
sum = 0;
for(int i = 1; i <= l; ++i)
sum += a[v[i]][j];
s[j] = s_col[j] - sum;
}
sort(s + 1, s + m + 1);
for(int i = c + 1; i <= m; ++i)
newSum += s[i];
if(newSum > sumMax) sumMax = newSum;
}
void make_bkt(int k){
for(int i = v[k - 1] + 1; i <= n; ++i){
v[k] = i;
if(k == l) aflu_solutie();
else make_bkt(k + 1);
}
}
int main()
{
f >> n >> m >> l >> c;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j){
f >> x;
if(n <= m){
a[i][j] = x;
s_col[j] += x;
}
else {
a[j][i] = x;
s_col[i] += x;
}
}
if(n > m) swap(n ,m), swap(l, c);
make_bkt(1);
g << sumMax;
return 0;
}