BZOJ 1283 费用流
思路:
最大费用最大流
i->i+1 连边k 费用0
i->i+m (大于n的时候就连到汇) 连边1 费用a[i]
//By SiriusRen
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 1005
#define M 2222222
#define mem(x,y) memset(x,y,sizeof(x))
int n,m,k,a[N];
int first[N],next[M],v[M],edge[M],cost[M],tot;
int vis[N],with[N],minn[N],d[N],ans;
void Add(int x,int y,int C,int E){edge[tot]=E,cost[tot]=C,v[tot]=y,next[tot]=first[x],first[x]=tot++;}
void add(int x,int y,int C,int E){Add(x,y,C,E),Add(y,x,-C,0);}
bool tell(){
mem(vis,0),mem(with,0),mem(minn,0x3f),mem(d,0x3f);
queue<int>q;q.push(0),d[0]=0;
while(!q.empty()){
int t=q.front();q.pop(),vis[t]=0;
for(int i=first[t];~i;i=next[i])
if(d[v[i]]>d[t]+cost[i]&&edge[i]){
minn[v[i]]=min(minn[t],edge[i]),with[v[i]]=i,d[v[i]]=d[t]+cost[i];
if(!vis[v[i]])vis[v[i]]=1,q.push(v[i]);
}
}return d[n+1]!=0x3f3f3f3f;
}
int zeng(){
for(int i=n+1;i;i=v[with[i]^1])
edge[with[i]]-=minn[n+1],edge[with[i]^1]+=minn[n+1];
return minn[n+1]*d[n+1];
}
int main(){
mem(first,-1),scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=n;i++)add(i,i+m<=n?i+m:n+1,-a[i],1);
for(int i=0;i<=n;i++)add(i,i+1,0,k);
while(tell())ans+=zeng();
printf("%d\n",-ans);
}