Pagini recente » Cod sursa (job #2547872) | Cod sursa (job #510874) | Cod sursa (job #2446818) | Cod sursa (job #2672600) | Cod sursa (job #2788812)
#include<iostream>
#include<fstream>
#include<cmath>
#include<algorithm>
using namespace std;
ifstream f("elimin.in");
ofstream g("elimin.out");
short v[1709][1709];
long long s[1709];
int nr1(int x){
int p=1,k=0;
while(p<=x){
k+=(p&x?1:0);
p*=2;
}
return k;
}
void clean(int n){
for(int i=1;i<=n;i++)
s[i]=0;
}
int main()
{
int n,m,r,c,p;
long long res,aux;
f>>n>>m>>r>>c;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
f>>(n>=m?v[i][j]:v[j][i]);
if(m>=n){
swap(n,m);
swap(r,c);
}
p = (1 << m);
res=0;
for(int i=0;i<p;i++)
if(nr1(i)==c){
clean(n);
aux=0;
for(int j=1;j<=m;j++)
if(!(i&(1<<(j-1))))
for(int l=1;l<=n;l++){
s[l]+=v[l][j];
aux+=v[l][j];
}
sort(s+1,s+n+1);
for(int j=1;j<=r;j++)
aux-=s[j];
res=max(res,aux);
}
g<<res<<'\n';
f.close();
g.close();
return 0;
}