题解:背包的变形+排序,首先我们能发现,我们对于每座城市最优的派兵数一定是某个选手派兵数2*+1,因为如果我们再多派也是浪费,这样我们可以把每座城市当作一个物品,重量就是某个选手派兵数*2+1,而权值就是有多少个选手当前城市派兵数*2小于我当前派兵数再乘以城市编号,我们可以在每次枚举城市时,把所有选手派兵数先排序,这样我们枚举当前派兵数时就可以知道有多少个城市能被自己占领,于是这题就变成经典的背包了
细节见代码注释:
#include<iostream>
#include<stack>
#include<list>
#include<set>
#include<vector>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<map>
#include<cstring>
#include<queue>
#include<iomanip>
#include<cmath>
#include<queue>
#include <bitset>
#include<unordered_map>
#ifndef local
#define endl '\n'
#endif */
#define mkp make_pair
using namespace std;
using std::bitset;
typedef long long ll;
typedef long double ld;
const int inf=0x3f3f3f3f;
const ll MAXN=2e6+10;
const ll N=2e5+100;
const ll mod=1e9+7;
const ll hash_p1=1610612741;
const ll hash_p2=805306457;
const ll hash_p3=402653189;
//-----------------------------------------------------------------------------------------------------------------*/
// ll head[MAXN],net[MAXN],to[MAXN],edge[MAXN]/*流量*/,cost[MAXN]//费用;
/*
void add(ll u,ll v,ll w,ll s){
to[++cnt]=v;net[cnt]=head[u];edge[cnt]=w;cost[cnt]=s;head[u]=cnt;
to[++cnt]=u;net[cnt]=head[v];edge[cnt]=0;cost[cnt]=-s;head[v]=cnt;
}
struct elemt{
int p,v;
};
-----------------------------------
求[1,MAXN]组合式和逆元
ll mi(ll a,ll b){
ll res=1;
while(b){
if(b%2){
res=res*a%mod;
}
a=a*a%mod;
b/=2;
}
return res;
}
ll fac[MAXN+10],inv[MAXN+10]
ll C(int m,int n){//组合式C(m,n);
if(!n){
return 1;
}
return fac[m]*(inv[n]*inv[m-n]%mod)%mod;
}
fac[0]=1;inv[0]=1;
for(ll i=1;i<=MAXN;i++){
fac[i]=(fac[i-1]*i)%mod;
inv[i]=mi(fac[i],mod-2);
}
---------------------------------
unordered_map<int,int>mp;
//优先队列默认小顶堆 , greater<int> --小顶堆 less<int> --大顶堆
priority_queue<elemt,vector<elemt>,comp>q;
struct comp{
public:
bool operator()(elemt v1,elemt v2){
return v1.v<v2.v;
}
};
set<int>::iterator it=st.begin();
*/
//emplace_back() 等于push_back(),但效率更高,传输pair时emplace_back(i,j)==push_back({i,j})
// vector<vector<int>>edge; 二维虚拟储存坐标
//-----------------------------------------------------------------------------------------------------------------*/
//map<int,bool>mp[N];
//emplace_back()
ll dp[20010];
vector<int>a[110];//每列元素
int main(){
/*cout<<setiosflags(ios::fixed)<<setprecision(8)<<ans<<endl;//输出ans(float)格式控制为8位小数(不含整数部分)*/
/*cout<<setprecision(8)<<ans<<endl;//输出ans(float)格式控制为8位小数(含整数部分)*/
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);//同步流
int s,n,m;
cin>>s>>n>>m;
for(int i=1;i<=s;i++){
for(int j=1;j<=n;j++){
int d;
cin>>d;
a[j].emplace_back(d);
}
}
for(int i=1;i<=n;i++){//枚举列
sort(a[i].begin(),a[i].end());//从小往大排序,这样就知道每次比多少个对手的驻军多了
for(int j=m;j>=0;j--){
for(int k=0;k<a[i].size();k++){//枚举当前派兵数(肯定是某地驻军的2倍)
if(j>=2*a[i][k]+1){
dp[j]=max(dp[j-2*a[i][k]-1]+i*(k+1),dp[j]);
}
}
}
}
cout<<dp[m]<<endl;
return 0;
}