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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

[HAOI2010]订货

發布時間:2025/3/15 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [HAOI2010]订货 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

某公司估計市場在第i個月對某產品的需求量為Ui,已知在第i月該產品的訂貨單價為di,上個月月底未銷完的單位產品要付存貯費用m,假定第一月月初的庫存量為零,第n月月底的庫存量也為零,問如何安排這n個月訂購計劃,才能使成本最低?每月月初訂購,訂購后產品立即到貨,進庫并供應市場,于當月被售掉則不必付存貯費。假設倉庫容量為S。

輸入輸出格式

輸入格式:
第1行:n, m, S (0<=n<=50, 0<=m<=10, 0<=S<=10000)

第2行:U1 , U2 , … , Ui , … , Un (0<=Ui<=10000)

第3行:d1 , d2 , …, di , … , dn (0<=di<=100)

輸出格式:
只有1行,一個整數,代表最低成本

輸入輸出樣例

輸入樣例#1:
3 1 1000
2 4 8
1 2 4

輸出樣例#1:
34

.
.
.
.
.
分析
這是一道費用流裸題

.
.
.
.
.
.
程序:

#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std;int n,m,S,cnt,last[55],s,t,dis[55],vis[55],pre[55],ans=0; struct edge {int from,to,c,w,next; }e[55*55*2]; queue<int> q;int read() {int x=0,f=1;char ch=getchar();while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; }void addedge(int u,int v,int c,int w) {e[++cnt].from=u;e[cnt].to=v;e[cnt].c=c;e[cnt].w=w;e[cnt].next=last[u];last[u]=cnt;e[++cnt].from=v;e[cnt].to=u;e[cnt].c=0;e[cnt].w=-w;e[cnt].next=last[v];last[v]=cnt;}bool spfa() {for (int i=s;i<=t;i++) dis[i]=2147483647; dis[s]=0;vis[s]=1; q.push(s);while (!q.empty()){int u=q.front();q.pop();for (int i=last[u];i;i=e[i].next)if (e[i].c&&(dis[u]+e[i].w<dis[e[i].to])) {dis[e[i].to]=dis[u]+e[i].w; pre[e[i].to]=i; if (!vis[e[i].to]) {vis[e[i].to]=1;q.push(e[i].to); }}vis[u]=0;}if (dis[t]<2147483647) return true; else return false; }void mcf() {int mn=2147483647,x=t;while (pre[x]) {mn=min(mn,e[pre[x]].c); x=e[pre[x]].from; }ans+=dis[t]*mn;x=t; while (pre[x]) {e[pre[x]].c-=mn; e[pre[x]^1].c+=mn; x=e[pre[x]].from; } }int main() {n=read();m=read();S=read();s=0;t=n+1;cnt=1;for (int i=1;i<=n;i++){int x=read();addedge(i,t,x,0); }for (int i=1;i<=n;i++){int x=read();addedge(s,i,2147483647,x); }for (int i=1;i<n;i++) addedge(i,i+1,S,m); while (spfa()) mcf(); printf("%d",ans); return 0; }

轉載于:https://www.cnblogs.com/YYC-0304/p/11094942.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的[HAOI2010]订货的全部內容,希望文章能夠幫你解決所遇到的問題。

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