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的更多相关文章

  1. 【codeforces 724E】Goods transportation

    [题目链接]:http://codeforces.com/problemset/problem/724/E [题意] 有n个城市; 这个些城市每个城市有pi单位的物品; 然后已知每个城市能卖掉si单位 ...

  2. 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 ...

  3. Goods transportation

    Goods transportation time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  4. 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 ...

  5. [codeforces724E]Goods transportation

    [codeforces724E]Goods transportation 试题描述 There are n cities located along the one-way road. Cities ...

  6. Codeforces 724E Goods transportation(最小割转DP)

    [题目链接] http://codeforces.com/problemset/problem/724/E [题目大意] 每个城市有pi的物品可以运出去卖,si个物品可以买, 编号小的城市可以往编号大 ...

  7. CodeForces E. Goods transportation【最大流+dp最小割】

    妙啊 首先暴力建图跑最大流非常简单,s向每个i连流量为p[i]的边,每个i向t连流量为s[i]的边,每个i向j连流量为c的边(i<j),但是会又T又M 考虑最大流=最小割 然后dp求最小割,设f ...

  8. 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 ...

  9. codeforces 724

    题目链接: http://codeforces.com/contest/724 A. Checking the Calendar time limit per test 1 second memory ...

随机推荐

  1. UDP 网络通信 C#

    接收端   using System; using System.Net; using System.Net.Sockets; using System.Text; using System.Thre ...

  2. DllImport dll中有些啥函数 及 dll中是否用到了别的dll

    在加载dll的时候不知道dll中有哪些接口怎么办,或者使用别人封装的东西时报出类似于“无法在 DLL“XXX.dll”中找到名为“XXX函数”的入口点.”     1.通过LordPE这个软件来看dl ...

  3. 有scp命令,传输文件却显示报错无此命令

    今天下午在一台服务器上使用scp命令向另外一台服务器传文件的时候,报此错误 bash: scp: command not found ,lost connection,以为是该服务器没有安装此命令,w ...

  4. composer错误收集

    1. Problem 1 - The requested package ** is satisfiable by ** but these conflict with your requiremen ...

  5. intelligencia.urlrewriter使用

    见github: https://github.com/sethyates/urlrewriter

  6. [EWS]在exchange中的标识符

    摘要 最近在用ews的方式开发邮箱服务,包括写邮件,查看某封邮件的详情,回复,全部回复及转发功能.在获取收件箱的时候,关于唯一标识符的问题.也有点困惑,在每个邮件item中,存在一个changeKey ...

  7. VS2010webConfig配置

    1.连接SqlServer数据库 <connectionStrings> <add name="ConnectionStringName" connectionS ...

  8. ls按时间排序输出文件列表

    文件转自:http://www.2cto.com/os/201303/197829.html ls按时间排序输出文件列表   首先,ls --help查看ls相关的与时间排序相关的参数:   > ...

  9. Memcached存储命令 - add

    Memcached add 命令用于将 value(数据值) 存储在指定的 key(键) 中. 如果 add 的 key 已经存在,则不会更新数据,之前的值将仍然保持相同,并且您将获得响应 NOT_S ...

  10. 分享php中四种webservice实现的简单架构方法及实例

    一:PHP本身的SOAP所有的webservice都包括服务端(server)和客户端(client).要使用php本身的soap首先要把该拓展安装好并且启用.下面看具体的code首先这是服务端实现: ...