Pagini recente » Cod sursa (job #582250) | Cod sursa (job #1043851) | Cod sursa (job #3177131) | Cod sursa (job #701485) | Cod sursa (job #2310322)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("elimin.in");
ofstream g("elimin.out");
int cnt1(int N)
{
int result=0;
while(N) N=N&(N-1),result++;
return result;
}
int N,M,R,C;
int A[17][8001];
int S[8001],smx;
int main(){
f>>N>>M>>R>>C;
if(N<=M)
{
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
f>>A[i][j];
}
else
{
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
f>>A[j][i];
swap(N,M),swap(R,C);
}
int L=(1<<N);
for(int k=0;k<L;k++)
{
if(cnt1(k)==R)
{
for(int i=0;i<M;S[i++]=0);
for(int i=0;i<N;i++)
if((k&(1<<i))==0)
for(int j=0;j<M;j++)
S[j]+=A[i][j];
sort(S,S+M);
int s=0;
for(int i=C;i<M;s+=S[i++]);
smx=max(smx,s);
}
}
g<<smx;
return 0;
}