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 ...
随机推荐
- 才知道创建数据表的后面int(M)的m居然和存储大小没有关系
之前一直以为,后面m代表有几个字节 MySQL 数据类型中的 integer types 有点奇怪.你可能会见到诸如:int(3).int(4).int(8) 之类的 int 数据类型.刚接触 MyS ...
- One Night Ultimate Werewolf Daybreak
http://beziergames.com/products/replacement-tiles-tokens-for-one-night-ultimate-werewolf http://www. ...
- 几个有用的JavaScript/jQuery代码片段(转)
1. 检查数据是否包含在Array中 //jQuery实现 jQuery.inArray("value", arr); // 使用方法: if( jQuery.inArray(&q ...
- struts2.3.16所需的基本的jar包---------SSH升级包不是整体全部都升级的
struts2.3.16所需的基本的jar包 jar包放多了就报Exception什么Unable to load....上网搜了半天也没有能解决的 下面所说的jar包放到WEB-INF/lib以 ...
- gradle init.gradle的文件配置 使用
init.gradle文件在build开始之前执行,所以你可以在这个文件配置一些你想预先加载的操作例如配置build日志输出.配置你的机器信息,比如jdk安装目录,配置在build时必须个人信息,比如 ...
- 本地自定义了404 和500 错误处理 部署到IIS上显示 服务器内部错误
问题如图 解决办法如下,在IIS上设置一下即可
- 2015年12月01日 GitHub入门学习(一)GitHub简介
序:Github理念是Social Coding(社会化编程).octocat是它的吉祥物. 一.Github与Git的区别与联系 区别:GIT是仓库,Github是提供一种将代码提交到Git仓库的服 ...
- 去除tabbar的灰线
去掉导航栏的边界灰线 [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBar ...
- 可编辑select
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- uva.10020 Minimal coverage(贪心)
10020 Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose t ...