分析
满足每天要求看做最大流,求最小花费
#include<bits/stdc++.h>
#define N 4005
#define M N*N*4
#define inf 0x3fffffff
#define LL long long
using namespace std;
int first[N],next[M],to[M],w[M],c[M],tot=1;
int n,p,m,f,t,s,r[N],st,ed;
int dis[N],vis[N],from[N],froms[N];
queue<int> q;
int read(){
int cnt=0,f=1;char ch=0;
while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
while(isdigit(ch))cnt=cnt*10+(ch-'0'),ch=getchar();
return cnt*f;
}
void add(int x,int y,int z,int f){
next[++tot]=first[x],first[x]=tot;
to[tot]=y,w[tot]=z,c[tot]=f;
}
bool bfs(){
memset(dis,127,sizeof(dis));
memset(vis,0,sizeof(vis));
int Inf = dis[0]; dis[st]=0 , vis[st]=1;
q.push(st);
while(!q.empty()){
int x=q.front(); q.pop(); vis[x]=0;
for(int i=first[x];i;i=next[i]){
int t=to[i]; if(!w[i]) continue;=
if(dis[t]>dis[x]+c[i]){
dis[t] = dis[x] + c[i];
from[t] = x , froms[t] = i;
if(!vis[t]) vis[t]=1 , q.push(t);
}
}
}return dis[ed] != Inf;
}
int calc(){
int u=ed , flow=inf;
while(u){
flow = min(flow , w[froms[u]]);
u=from[u];
}u=ed;
while(u){
w[froms[u]] -= flow;
w[froms[u]^1] += flow;
u=from[u];
}return flow;
}
void dinic(){
LL ans=0;
while(bfs()) ans += (LL) calc() * dis[ed];
printf("%lld",ans);
}
int main(){
n=read(); st=0 , ed=n*2+1;
for(int i=1;i<=n;i++) r[i]=r[i+n]=read();
p=read(),m=read(),f=read(),t=read(),s=read();
for(int i=1;i<=n;i++) add(st,i,r[i],0),add(i,st,0,0);
for(int i=n+1;i<=n*2;i++) add(i,ed,r[i],0),add(ed,i,0,0);
for(int i=n+1;i<=n*2;i++) add(st,i,r[i],p),add(i,st,0,-p);
for(int i=1;i<=n;i++)
for(int j=i+n+m;j<=n*2;j++)
add(i,j,inf,f),add(j,i,0,-f);
for(int i=1;i<=n;i++)
for(int j=i+n+t;j<=n*2;j++)
add(i,j,inf,s),add(j,i,0,-s);
for(int i=1;i<n;i++) add(i,i+1,inf,0),add(i+1,i,0,0);
dinic(); return 0;
}