日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

P2517-订货【网络流,费用流】

發布時間:2023/12/3 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 P2517-订货【网络流,费用流】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

正題

AC鏈接:
https://www.luogu.org/record/show?rid=7949532


大意

有n個月,每個月商品價格di,需求量Ui。有容量為S的倉庫,一個商品匯存一個月要m。求最低成本


解題思路

首先是月份做為點,成本作為費用,需求作為容量。
剛開始想的是專門做一個點作為倉庫,后來發現其實可以直接向下連邊。
然后就是這樣構圖:

然后求費用流就好了


代碼

#include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct line{int to,w,c,next; }a[2001]; int tot,n,m,s,t,f[601],ls[601],tail,answer; int state[601],x,y,w,c,ans,head,pre[601],S; bool v[601]; void addl(int x,int y,int w,int c) {a[++tot].to=y;a[tot].w=w;a[tot].c=c;a[tot].next=ls[x];ls[x]=tot;a[++tot].to=x;a[tot].w=0;a[tot].c=-c;a[tot].next=ls[y];ls[y]=tot; } bool spfa() {memset(f,127/3,sizeof(f));memset(v,0,sizeof(v));head=0;tail=1;v[s]=true;state[1]=s;f[s]=0;while (head!=tail){head=head%500+1;int x=state[head];for (int q=ls[x];q;q=a[q].next){int y=a[q].to;if (a[q].w&&f[x]+a[q].c<f[y]){f[y]=f[x]+a[q].c;pre[y]=q;if (!v[y]){v[y]=true;tail=tail%500+1;state[tail]=y;}}}v[x]=false;}if (f[t]>=707406378) return 0;else return 1; } void upway() {int k=2147483647,now=t;while (now!=s){k=min(k,a[pre[now]].w);now=a[pre[now]^1].to;}ans+=f[t]*k;now=t;answer+=k;while (now!=s){a[pre[now]].w-=k;a[pre[now]^1].w+=k;now=a[pre[now]^1].to;} } int main() {tot=1;scanf("%d%d%d",&n,&m,&S);s=n+1;t=n+2;for (int i=1;i<=n;i++)scanf("%d",&x),addl(i,t,x,0);//完成訂單for (int i=1;i<=n;i++)scanf("%d",&x),addl(s,i,1e9,x);//進貨for (int i=1;i<n;i++)addl(i,i+1,S,m);//存while (spfa()){upway();}printf("%d",ans); }

總結

以上是生活随笔為你收集整理的P2517-订货【网络流,费用流】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。