poweroj1745: 餐巾计划问题
最小费用最大流。
每天拆成两个点,i表示用完的餐巾,i+n表示干净的餐巾。
s向i连容量为ri费用为0的边,表示每天用脏的ri条餐巾。
i+n向t连容量为ri费用为0的边,表示每天需要用ri条餐巾。
s向1+n连容量为inf费用为p的边,表示新买进的干净餐巾,需要新买的在第一天全买了。
两种洗法都是,i 向 i+time+n 连容量为xx,费用为cost的边,表示第i天用完就洗干净放在洗完的第一天看哪天要用。
i+n向i+1+n连容量为Inf,费用为0的边,表示前一天没用的(新买的/洗干净的)干净餐巾,免费留到下一天用。
不明白为什么其他人都要把脏的留到什么时候需要再洗,不应该立刻洗了屯着么。。
//Achen
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<ctime>
const int N=1e6+,inf=0x7fffffff;
typedef long long LL;
using namespace std;
int n,pp,kt,kv,mt,mv; template<typename T> void read(T &x) {
T f=; x=; char ch=getchar();
while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
if(ch=='-') f=-,ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
} struct edge {
int u,v,fl,cap,cost,nx;
edge(){}
edge(int u,int v,int fl,int cap,int cost,int nx):u(u),v(v),fl(fl),cap(cap),cost(cost),nx(nx){}
}e[N]; int fir[N],ecnt=;
void add(int u,int v,int cap,int cost) {
e[++ecnt]=edge(u,v,,cap,cost,fir[u]); fir[u]=ecnt;
e[++ecnt]=edge(v,u,,,-cost,fir[v]); fir[v]=ecnt;
} int vis[N],dis[N],p[N],tot;
queue<int>que;
int spfa(int s,int t) {
for(int i=;i<=tot;i++) vis[i]=,dis[i]=inf;
que.push(s); dis[s]=;
while(!que.empty()) {
int x=que.front();
que.pop(); vis[x]=;
for(int i=fir[x];i;i=e[i].nx)
if(e[i].cap>e[i].fl) {
int y=e[i].v;
if(dis[y]>dis[x]+e[i].cost) {
dis[y]=dis[x]+e[i].cost;
p[y]=i;
if(!vis[y]) {
vis[y]=;
que.push(y);
}
}
}
}
return dis[t]!=inf;
} int calc(int s,int t) {
int fl=inf,res=;
for(int i=t;i!=s;i=e[p[i]].u)
fl=min(fl,e[p[i]].cap-e[p[i]].fl),
res+=e[p[i]].cost;
for(int i=t;i!=s;i=e[p[i]].u)
e[p[i]].fl+=fl,e[p[i]^].fl-=fl;
return fl*res;
} int max_flow(int s,int t) {
int res=;
while(spfa(s,t))
res+=calc(s,t);
return res;
} int main() {
read(n); read(pp); read(kt);
read(kv); read(mt); read(mv);
int s=n*+,t=s+; tot=t;
add(s,+n,inf,pp);
for(int i=;i<=n;i++) {
int xx; read(xx);
add(s,i,xx,);
add(i+n,t,xx,);
if(i+<=n) add(i+n,i+n+,inf,);
if(i+kt<=n) add(i,i+n+kt,xx,kv);
if(i+mt<=n) add(i,i+n+mt,xx,mv);
}
int ans=max_flow(s,t);
printf("%d\n",ans);
return ;
}
poweroj1745: 餐巾计划问题的更多相关文章
- P1251 餐巾计划问题
P1251 餐巾计划问题 题目描述 一个餐厅在相继的 N 天里,每天需用的餐巾数不尽相同.假设第 iii 天需要 rir_iri块餐巾( i=1,2,...,N).餐厅可以购买新的餐巾,每块餐巾的费 ...
- LibreOJ #6008. 「网络流 24 题」餐巾计划 最小费用最大流 建图
#6008. 「网络流 24 题」餐巾计划 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据 题目描述 ...
- Libre 6008 「网络流 24 题」餐巾计划 (网络流,最小费用最大流)
Libre 6008 「网络流 24 题」餐巾计划 (网络流,最小费用最大流) Description 一个餐厅在相继的N天里,第i天需要Ri块餐巾(i=l,2,-,N).餐厅可以从三种途径获得餐巾. ...
- 洛谷 P1251 餐巾计划问题(线性规划网络优化)【费用流】
(题外话:心塞...大部分时间都在debug,拆点忘记加N,总边数算错,数据类型标错,字母写错......) 题目链接:https://www.luogu.org/problemnew/show/P1 ...
- BZOJ1229 & 洛谷2917:[USACO2008 NOV]toy 玩具 & 洛谷4480:[BJWC2018]餐巾计划问题——题解
标题很长emmm…… [USACO2008 NOV]toy 玩具 https://www.luogu.org/problemnew/show/P2917 https://www.lydsy.com/J ...
- 初识费用流 模板(spfa+slf优化) 餐巾计划问题
今天学习了最小费用最大流,是网络流算法之一.可以对于一个每条边有一个容量和一个费用(即每单位流的消耗)的图指定一个源点和汇点,求在从源点到汇点的流量最大的前提下的最小费用. 这里讲一种最基础也是最好掌 ...
- AC日记——餐巾计划问题 洛谷 P1084
餐巾计划问题 思路: 氧气优化水过: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 4005 #define ...
- LOJ #6008. 「网络流 24 题」餐巾计划
#6008. 「网络流 24 题」餐巾计划 题目描述 一个餐厅在相继的 n nn 天里,每天需用的餐巾数不尽相同.假设第 i ii 天需要 ri r_iri 块餐巾.餐厅可以购买新的餐巾,每块餐 ...
- [luogu_P1251][LOJ#6008]「网络流 24 题」餐巾计划
[luogu_P1251][LOJ#6008]「网络流 24 题」餐巾计划 试题描述 一个餐厅在相继的 \(N\) 天里,第 \(i\) 天需要 \(R_i\) 块餐巾 \((i=l,2,-,N)\) ...
随机推荐
- 满血复活前的记录(持续更新ing)
时隔一年重新开启算法竞赛征程. 该记录大多为老课件.已经做过的习题重做和已经看过的书本重看 7.21 下午到山大 娄晨耀basic_algorithm课件中的内容: 复习线性筛原理 复习差分 做完Co ...
- Imageview 图片按比例缩放
只需要在 布局文件中 加入 android:adjustViewBounds="true"这行代码即可 它会让图片进行等比例的拉伸展示
- SQFREE - Square-free integers
SQFREE - Square-free integers 求n以内,约数中不包含任意一个平方数的个数,\(n≤10^{14}\). 解 显然为约数计数问题,于是想办法转换为代数问题,不难列出 \[a ...
- python网络框架Twisted
什么是Twisted Twisted是一个用python语言写的事件驱动网络框架,它支持很多种协议,包括UDP,TCP,TLS和其他应用层协议,比如HTTP,SMTP,NNTM,IRC,XMPP/Ja ...
- mybatis接口映射
通过sqlSession.getMapper();方法获取映射的接口及方法 sqlSession调用Configuration的getMapper方法,方法中使用了mapperRegistry.get ...
- <meta>标记
<meta>的主要作用: 是提供网页的元素信息 属性: http-equiv: 功能: 默认http协议文件头信息,当信息从服务器端传到客户端时,让浏览器正确的是显示, http_equi ...
- 引用不了XXservice,怎么办?
1.tEdasArchiveLogService = (TEdasArchiveLogService) SpringContextHolder.getBean("TEdasArchiveLo ...
- elasticsearch 中文API river
river-jdbc 安装 ./bin/plugin --install jdbc --url http://xbib.org/repository/org/xbib/elasticsearch/pl ...
- Leetcode60. Permutation Sequence第k个排列
给出集合 [1,2,3,-,n],其所有元素共有 n! 种排列. 按大小顺序列出所有排列情况,并一一标记,当 n = 3 时, 所有排列如下: "123" "132&qu ...
- Windows API 23 篇 WTSQuerySessionInformation
函数原型:BOOLWINAPIWTSQuerySessionInformationW( IN ...