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. linux手动或者自动启动oracle11g的服务 Oracle 自动启动脚本

    手动启动: [oracle@localhost ~]$ sqlplus SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 26 23:39:52 2 ...

  2. JavaScript学习笔记——数组

    javascript数组数组是一个可以存储 一组 或是 一系列 相关数据 的 容器. 一.为什么要使用数组. (1)为了解决大量相关数据的存储和使用的问题. (2)模拟真是的世界. 二.如何创建数组 ...

  3. URL组分

    url通常包含多个组成部分,在js中可通过location对象获取其中各项信息 访问http://mp.weixin.qq.com/s?__biz=MjM5NjA0NjgyMA==&mid=2 ...

  4. 使用node的插件UglifyJs来合并和压缩文件

    code: var fs = require('fs'); var jsp = require("./UglifyJS-master/uglify-js").parser; var ...

  5. JAVA中的聚集和组合的区别和联系

    选自<JAVA语言程序设计-基础篇(原书第8版)> 定义:一个对象可以包含另一个对象.这两个对象之间的关系称为组合(composition). 组合实际上是聚集关系的一种特殊形式.聚集模拟 ...

  6. C# volatile关键字

    ; public int GetAge() { return Age; } 如上例子,调用GetAge()得到的是“主”内存区域的Age数值.用volatile修饰后的变量不允许有不同于“主”内存区域 ...

  7. 使用CFURLCreateStringByAddingPercentEscapes进行URL编码

    iOS程序访问HTTP资源时需要对URL进行UTF8编码,特酷吧在之前一直都喜欢使用NSString的stringByAddingPercentEscapesUsingEncoding方法进行编码.今 ...

  8. 时间处理工具类DateUtils

    public class DateUtils {         public static final String                            SHORT_DATE    ...

  9. 如何在发布博客时插入复杂公式——Open Live Writer

    1.http://latex.codecogs.com/eqneditor/editor.php 2.使用Word发布

  10. 清北暑假模拟day1 生活

    /* 数字三角形,要求第K大的值,可以推知,如果得知k的范围,那么一定是在上一行可转移状态的对应范围内(反证法可以证明),这个在背包九讲里也有提及 */ #include<cstdio> ...