Codeforces 724 E Goods transportation
Description
有 \(n\) 个点,每个点有一个入流和出流,每个点与编号比它大的点连边,容量为 \(c\) ,求最大流.
Sol
DP.
这种特殊的图可以DP,把最大流转化成最小割.
最小割就是 \(\sum s_i,i\in S + \sum p_j,j \in T + c \sum [i \in S][j\in T]\) .
最后一个式子其实就是 \(S\) 与 \(T\) 的割边.
\(f[i][j]\) 表示前 \(i\) 个点有 \(j\) 个点 \(\in S\)
转移就是对于一个点加入 \(S\) 还是加入 \(T\) 取 \(min\)
\(f[i][j]=min\{f[i][j-1]+s[i],f[i][j]+j*c+p[i]\}\)
倒序枚举即可 复杂度 \(O(\frac {n(n-1)} {2})\)
Code
#include<cstdio>
#include<iostream>
using namespace std; typedef long long LL;
const int N = 10005;
const LL INF = 1LL<<60; int n,c;LL ans;
int p[N],s[N];
LL f[N]; inline int in(int x=0,char ch=getchar()){ while(ch>'9'||ch<'0') ch=getchar();
while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x; }
int main(){
n=in(),c=in();
for(int i=1;i<=n;i++) p[i]=in();
for(int i=1;i<=n;i++) s[i]=in();
for(int i=1;i<=n;i++) f[i]=INF; for(int i=1;i<=n;i++){
for(int j=i;j;j--)
f[j]=min(f[j-1]+s[i],f[j]+(LL)j*c+p[i]);
f[0]+=p[i];
}
ans=INF; // for(int i=0;i<=n;i++) cout<<f[i]<<" ";cout<<endl; for(int i=0;i<=n;i++) ans=min(ans,f[i]);
return cout<<ans<<endl,0;
}
Codeforces 724 E Goods transportation的更多相关文章
- 【codeforces 724E】Goods transportation
[题目链接]:http://codeforces.com/problemset/problem/724/E [题意] 有n个城市; 这个些城市每个城市有pi单位的物品; 然后已知每个城市能卖掉si单位 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation 动态规划
E. Goods transportation 题目连接: http://codeforces.com/contest/724/problem/E Description There are n ci ...
- Goods transportation
Goods transportation time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E - Goods transportation 最大流转最小割转dp
E - Goods transportation 思路:这个最大流-> 最小割->dp好巧妙哦. #include<bits/stdc++.h> #define LL long ...
- [codeforces724E]Goods transportation
[codeforces724E]Goods transportation 试题描述 There are n cities located along the one-way road. Cities ...
- Codeforces 724E Goods transportation(最小割转DP)
[题目链接] http://codeforces.com/problemset/problem/724/E [题目大意] 每个城市有pi的物品可以运出去卖,si个物品可以买, 编号小的城市可以往编号大 ...
- CodeForces E. Goods transportation【最大流+dp最小割】
妙啊 首先暴力建图跑最大流非常简单,s向每个i连流量为p[i]的边,每个i向t连流量为s[i]的边,每个i向j连流量为c的边(i<j),但是会又T又M 考虑最大流=最小割 然后dp求最小割,设f ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation (非官方贪心解法)
题目链接:http://codeforces.com/contest/724/problem/E 题目大意: 有n个城市,每个城市有pi件商品,最多能出售si件商品,对于任意一队城市i,j,其中i&l ...
- codeforces 724
题目链接: http://codeforces.com/contest/724 A. Checking the Calendar time limit per test 1 second memory ...
随机推荐
- sql编程小结
对照mysql5.1手册,对这几天学的sql编程进行小结,主要涉及触发器.存储过程.权限管理.主从分离等,权当抛砖引玉,高手请略过. 一.触发器 通俗的说就是在指定的数据表增删改的前或后触发执行特定的 ...
- (新手向)基于Bootstrap的简单轮播图的手机实现
个人电脑里存了不少适合手机欣赏的图片,但是放手机里看是件很占据资源的事.鉴于家里有一台电脑经常开着,正好用来做家庭局域网共享,于是笔者就设想通过一种比较简单环保的思路.通过手机访问电脑内的图片. 首先 ...
- C#--中实现邮件发送
MailMessage mailmessage = new MailMessage(); mailmessage.To.Add("接受邮箱");//可以添加多个接收邮箱 mailm ...
- ast模块
有这么一个需求,你想从文件中读取字典,方法有很多,这里用的是ast模块 import ast with open("account","r",encoding= ...
- 使用docker安装lamp
docker search -s 10 lamp #搜索被收藏或使用较多的LAMP镜像,小伙伴们都推荐使用tutum/lamp docker pull tutum/lamp #下载镜像 #使用默认方式 ...
- Quartz.NET总结(三)Quartz 配置
前两篇文章,已经介绍了Quartz.NET的使用和Cron表达式表达式的写法,今天说一说Quartz的配置,Quartz相关的配置有三个quartz.config.quartz_jobs.xml.lo ...
- Rendering Paths
渲染路径 Rendering Paths http://game.ceeger.com/Manual/RenderingPaths.html 延迟光照渲染路径的细节 Deferred Lighting ...
- CSS中常见的位置(position)属性
常用的位置属性列表: position(top.bottom.left.right) .overflow.z-index position用法: 值 描述 relative 相对定位,原位置仍占用空间 ...
- Apache配置--用户认证(针对目录访问)-update2015-05-02
通过Apache配置可以限制用户对目录的访问,会弹出像phpadmin一样的登陆框. ========================================================= ...
- oss cmd
osscmd是基于python 2.5.4(其他版本没有试过),用来操作OSS的,可使用命令行来上传和下载文件. 下载地址:http://storage.aliyun.com/leo/osscmd.t ...