Pagini recente » Cod sursa (job #663409) | Cod sursa (job #1635521) | Cod sursa (job #1284503) | Cod sursa (job #1001817) | Cod sursa (job #1746827)
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int sumaPeColoana[100],sumaPeLinii[100],matriceData[100][100],vectorCombinari[100],m,n,r,c,sumaMaxima;
void citireDateIntrare()
{
cin>>m>>n>>r>>c;
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
{
cin>>matriceData[i][j];
sumaPeLinii[i]+=matriceData[i][j];
}
}
void determinareSuma()
{
int sumaProvizorie=0;
for(int j=1; j<=n; j++)
sumaPeColoana[j]=0;
for(int j=1; j<=n; j++)
{for(int i=1; i<=m-r; i++)
sumaPeColoana[j]+=matriceData[vectorCombinari[i]][j];
}
for(int i=1; i<=m-r; i++)
sumaProvizorie+=sumaPeLinii[vectorCombinari[i]];
sort(sumaPeColoana+1,sumaPeColoana+n+1);
for(int i=1; i<=c; i++)
sumaProvizorie-=sumaPeColoana[i];
if(sumaMaxima<sumaProvizorie)
sumaMaxima=sumaProvizorie;
}
void generareCombinari(int x)
{
if(x==m-r+1)
{
determinareSuma();
return;
}
for(int i=vectorCombinari[x-1]+1; i<=n; i++)
{
vectorCombinari[x]=i;
generareCombinari(x+1);
}
}
int main()
{
freopen("elimin.in","r",stdin);
freopen("elimin.out","w",stdout);
citireDateIntrare();
generareCombinari(1);
cout<<sumaMaxima;
return 0;
}