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. 自然语言7_NLTK中文语料库sinica_treebank

    http://www.hankcs.com/program/python/nltk-chinese-corpus-sinica_treebank.html NLTK包含Sinica (中央研究院)提供 ...

  2. Eclipse学习笔记——快捷键

    alt+/ 直接呼出要重写的方法 ctrl+1 快速修复(没导包,没抛出异常等等) ctrl+shift+o 导包 ctrl+shift+F 格式化代码块(自动给代码排版) alt+方向键 向前向后( ...

  3. Latex论文写作-Texsdudio 快捷键总结

    Latex论文写作-Texsdudio 快捷键总结  The keyboard shortcuts can be modified at Options -> Shortcuts. The fo ...

  4. 创建守护进程步骤与setsid() -- linux deamon进程

    原创:http://www.cnblogs.com/mickole/p/3188321.html 一,守护进程概述 Linux Daemon(守护进程)是运行在后台的一种特殊进程.它独立于控制终端并且 ...

  5. log4j2 使用

    转载自 Blog of 天外的星星: http://www.cnblogs.com/leo-lsw/p/log4j2tutorial.html Log4j 2的好处就不和大家说了,如果你搜了2,说明你 ...

  6. zabbix特性

    在知道zabbix是什么之后,我们最关心的是zabbix有什么特性,了解特性之后,我们才能决定是否会使用zabbix,以及zabbix是否适合我们. 概述 Zabbix是一个高度集成的网络监控套件,通 ...

  7. SQL之按两个字段分类汇总

    目的: 同时按"游戏代号"和"礼包名"分类汇总,然后获取下拉框的数据.  如下图所示: SQL查询 select game,giftname from qyg_ ...

  8. asp.net mvc ClaimsIdentity 授权研究 (还是测试版 有bug)

      安装 Microsoft.Owin.Host.SystemWeb Identity.Core Microsoft.Owin.Security.Cookies 在是startup.cs做如下修改 p ...

  9. php:Header

    转自鸟哥的博客: http://www.laruence.com/2007/12/16/308.html PHP header()the function declaration: void head ...

  10. PHP中获取内网用户MAC地址(WINDOWS/linux)的实现代码

    做一个内网根据MAC地址自动登录的应用,在WINDOW 2003可以正常使用,函数如下   复制代码 代码如下: function ce_getmac() { if(PHP_OS == 'WINNT' ...