CF724E Goods transportation
最大流既视感
然后
TLEMLE既视感
然后
最大流=最小割
然后
dp[i][j]前i个点j个点在S集合,最小割
然后
dp[i][j]=min(dp[i-1][j]+p[i]+j*c,dp[i-1][j-1]+s[i])考虑i点和T的边要不要断
然后
滚动数组优化一下,O(n^2)过10000
#include<bits/stdc++.h>
#define reg register int
#define il inline
#define numb (ch^'0')
using namespace std;
typedef long long ll;
il void rd(int &x){
char ch;x=;bool fl=false;
while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
for(x=numb;isdigit(ch=getchar());x=x*+numb);
(fl==true)&&(x=-x);
}
namespace Miracle{
const int N=+;
const ll inf=0x3f3f3f3f3f3f3f3f;
int n,c;
int p[N],s[N];
ll dp[][N];
ll ans;
int main(){
rd(n);rd(c);
for(reg i=;i<=n;++i) rd(p[i]);
for(reg i=;i<=n;++i) rd(s[i]);
int tmp=;
for(reg i=;i<=n;++i){
tmp^=;
memset(dp[tmp],0x3f,sizeof dp[tmp]);
for(reg j=;j<=i;++j){
if(j) dp[tmp][j]=min(dp[tmp^][j]+p[i]+(ll)j*c,dp[tmp^][j-]+s[i]);
else dp[tmp][j]=dp[tmp^][j]+p[i]+(ll)j*c;
}
}
ans=inf;
for(reg j=;j<=n;++j) ans=min(ans,dp[tmp][j]);
cout<<ans;
return ;
} }
signed main(){
Miracle::main();
return ;
} /*
Author: *Miracle*
Date: 2018/12/29 14:21:38
*/
思路:
最大流可以想到。但是边数太多
最小割=最大流而且最小割非常直观可以操作,而且网络流的图非常简单有规律
最小割dp就非常合适了。
CF724E Goods transportation的更多相关文章
- CF724E Goods transportation 最小割 DP
照惯例CF的题不放原题链接... 题意:一个序列上有n个点,每个点有权值pi和si.表示这个点一开始有pi个物品,最多可以卖出si个物品,每个点都可以把物品向编号更大的点运输,但是对于i < j ...
- 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 动态规划
E. Goods transportation 题目连接: http://codeforces.com/contest/724/problem/E Description There are n ci ...
- 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 ...
- 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 E Goods transportation
Description 有 \(n\) 个点,每个点有一个入流和出流,每个点与编号比它大的点连边,容量为 \(c\) ,求最大流. Sol DP. 这种特殊的图可以DP,把最大流转化成最小割. 最小割 ...
- 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 ...
随机推荐
- apache+php+mysql开发环境搭建
一.Apache 因为Apache官网只提供源代码,如果要使用必须得自己编译,这里我选择第三方安装包Apache Lounge. 进入Apachelounge官方下载地址:http://w ...
- List和Turple
List 格式:classmates = ['Michael', 'Bob', 'Tracy'] 读取list长度用:len(classmetes) 索引:索引正向从0开始,逆向从-1开始 在末尾增加 ...
- android AVD创建
参数详解:AVD name:是要填写的虚拟机名称,这个自己随便取名就行了,要纯英文和数字组成Device:这里是要选择模拟的设备,一般选择3.2*QVGA(ADP2)(320*480: mdpi)这个 ...
- JavaScript 字符串 & Math & Date
字符串 字符串就是零个或多个排在一起的字符,放在单引号或双引号之中. 'abc' "abc" 单引号字符串的内部,可以使用双引号.双引号字符串的内部,可以使用单引号. 'key=& ...
- spring 整合hibernate注解时候,出现“Unknown entity: com.ssh.entry.Admin; nested exception is org.hibernate.MappingException: Unknown entity: com.ssh.entry.Admin”异常的问题
今天学习使用ssh框架的时候,出现一个异常,弄了好久才找到,在这记录一下,我的sb错误1.spring整合hibernate,取代*.hbm.xml配置文件 在applicationContext ...
- 由一个hash字符串生成多个子hash字符串
通过存储一个head hash,然后把子hash放到网络中 当然,也可以像默克尔树那样的,生成多级的子hash ,可以通过规则配置不同的hash 生成方式.倒置的默克尔树 我有一个文件,然后我把她分隔 ...
- 自测之Lesson3:makefile
题目:编写一个makefile文件,要求编译当前目录内的所有.c文件. 完成代码: .PHONY:clean all SRC=$(wildcard *.c) BIN=$(SRC:%.c=%) all: ...
- Notes of the scrum meeting before publishing(12.19)
meeting time:18:30~20:30p.m.,December 19th,2013 meeting place:3号公寓一层 attendees: 顾育豪 ...
- Java异常(Exception)
Java异常:运行期出现的错误 1. Java异常是Java提供的用于处理程序中错误的一种机制: 2. 错误指的是程序运行期间发生的异常事件,如除零溢出.数组下标越界.读取的文件不存在.... 3. ...
- 修改IntelliJ IDEA字体