Pagini recente » Cod sursa (job #472946) | Cod sursa (job #1035111) | Cod sursa (job #2637489) | Cod sursa (job #395106) | Cod sursa (job #2314864)
#include<fstream>
#include<algorithm>
#define nmax 2001
using namespace std;
ifstream fin("elimin.in");
ofstream fout("elimin.out");
int n,m,c,r;
int a[nmax][nmax];
int x[nmax];
long long mx;
int b[nmax];
void back(int k)
{
if(k>c)
{
int i,j;
int viz[nmax]={0};
for(i=1; i<=k; ++i) ///coloanele eliminate
viz[x[i]]++;
int b[nmax];
int ct=0;
for(i=1; i<=n; i++)
{int sum=0;
for(j=1; j<=m; j++)
if(viz[j]==0) sum+=a[i][j];
b[++ct]=sum;
}
sort(b+1,b+ct+1);
int sum_tot=0;
for(i=r+1;i<=n; i++) sum_tot+=b[i];
if(sum_tot>mx) {mx=sum_tot;}
}
else
{
int i;
for(i=x[k-1]+1; i<=m-c+k; ++i)
{ x[k]=i;
back(k+1);
}
}
}
int main()
{
fin>>n>>m>>r>>c;
int i,j;
if(n>=m)
{
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
fin>>a[i][j];
}
else
{
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
fin>>a[j][i];
swap(m,n);
swap(r,c);
}
back(1);
fout<<mx;
return 0;
}