Pagini recente » Cod sursa (job #1090386) | Cod sursa (job #129917) | Cod sursa (job #1566732) | Cod sursa (job #658252) | Cod sursa (job #169481)
Cod sursa(job #169481)
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,m,r,c,s[600];
int nr[550][550],sol[20],lin[550],col[550];
int suma;
void back1(int poz,int elim){
if(poz>m+1)
return;
if(elim==r){
int i,j,sum;
for(i=1;i<=n;++i){
s[i]=0;
for(j=1;j<=m;++j){
if(!sol[j])
s[i]+=nr[j][i];
}
}
sort(s+1,s+n+1);
sum=0;
for(i=c+1;i<=n;++i)
sum+=s[i];
suma=suma<sum?sum:suma;
}
else{
sol[poz]=1;
back1(poz+1,elim+1);
sol[poz]=0;
back1(poz+1,elim);
}
}
void back2(int poz,int elim){
if(poz>n+1)
return;
if(elim==c){
int i,j,sum;
for(i=1;i<=m;++i){
s[i]=0;
for(j=1;j<=n;++j){
if(!sol[j])
s[i]+=nr[i][j];
}
}
sort(s+1,s+m+1);
sum=0;
for(i=r+1;i<=m;++i)
sum+=s[i];
suma=suma<sum?sum:suma;
}
else{
sol[poz]=1;
back1(poz+1,elim+1);
sol[poz]=0;
back1(poz+1,elim);
}
}
int main(){
freopen("elimin.in","r",stdin);
freopen("elimin.out","w",stdout);
int i,j;
suma=-2100000000;
scanf("%d%d%d%d",&m,&n,&r,&c);
for(i=1;i<=m;++i){
for(j=1;j<=n;++j){
scanf("%d",&nr[i][j]);
lin[i]+=nr[i][j];
col[j]+=nr[i][j];
}
}
if(m<=n)
back1(1,0);
else
back2(1,0);
printf("%d\n",suma);
fclose(stdin);
fclose(stdout);
return 0;
}