题意:


思路:



#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 18;
int n,m,k;
int a[N][N];
int main(){
scanf("%d%d%d",&n,&m,&k);
int sum = 0;
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
scanf("%d",&a[i][j]);
sum += a[i][j];
}
}
if(k >= min(n,m)) {printf("%d\n",sum);return 0;}
//枚举行
int mx = 0;
for(int s = 0;s < (1<<n);s++){
int cnt = __builtin_popcount(s);
if(cnt > k || k - cnt > m) continue;
int res = 0;
for(int i = 0;i < n;i++){
if((s >> i)&1){
for(int j = 0;j < m;j++){
res += a[i][j];
}
}
}
vector<int> v;//贪心列
for(int j = 0;j < m;j++){
int ret = 0;
for(int i = 0;i < n;i++){
if(!((s>>i)&1)){
ret += a[i][j];
}
}
v.push_back(ret);
}
sort(v.begin(),v.end(),greater<int>());
for(int i = 0;i < k - cnt && i < m;i++){
res += v[i];
}
mx = max(res,mx);
}
printf("%d\n",mx);
return 0;
}