Goods transportation
2 seconds
256 megabytes
standard input
standard output
There are n cities located along the one-way road. Cities are numbered from 1 to n in the direction of the road.
The i-th city had produced pi units of goods. No more than si units of goods can be sold in the i-th city.
For each pair of cities i and j such that 1 ≤ i < j ≤ n you can no more than once transport no more than c units of goods from the city i to the city j. Note that goods can only be transported from a city with a lesser index to the city with a larger index. You can transport goods between cities in any order.
Determine the maximum number of produced goods that can be sold in total in all the cities after a sequence of transportations.
The first line of the input contains two integers n and c (1 ≤ n ≤ 10 000, 0 ≤ c ≤ 109) — the number of cities and the maximum amount of goods for a single transportation.
The second line contains n integers pi (0 ≤ pi ≤ 109) — the number of units of goods that were produced in each city.
The third line of input contains n integers si (0 ≤ si ≤ 109) — the number of units of goods that can be sold in each city.
Print the maximum total number of produced goods that can be sold in all cities after a sequence of transportations.
3 0
1 2 3
3 2 1
4
5 1
7 4 2 1 0
1 2 3 4 5
12
4 3
13 10 7 4
4 7 10 13
34
分析:考虑最大流等于最小割,从小到大dp;
dp[i][j]表示前i个点有j个点在最小割点集里,
则dp[i][j]=min(dp[i-1][j-1]+s[i],dp[i-1][j]+j*c+p[i]);
dp[i-1][j-1]+s[i]表示i留在s-割的代价,dp[i-1][j]+j*c+p[i]表示i留在t-割,除了要花费p[i]外,还要花费j*c的代价;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<ll,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
const int maxn=1e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t;
ll p[maxn],s[maxn],ans[maxn],c;
int main()
{
int i,j;
scanf("%d%lld",&n,&c);
rep(i,,n)scanf("%lld",&p[i]);
rep(i,,n)scanf("%lld",&s[i]);
rep(i,,n)
{
ans[i]=1e18;
for(j=i;j>=;j--)
{
ans[j]=min(ans[j]+j*c+p[i],ans[j-]+s[i]);
}
ans[]+=p[i];
}
ll ret=1e18;
rep(i,,n)ret=min(ret,ans[i]);
printf("%lld\n",ret);
//system("Pause");
return ;
}
Goods transportation的更多相关文章
- 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,把最大流转化成最小割. 最小割 ...
- CF724E Goods transportation 最小割 DP
照惯例CF的题不放原题链接... 题意:一个序列上有n个点,每个点有权值pi和si.表示这个点一开始有pi个物品,最多可以卖出si个物品,每个点都可以把物品向编号更大的点运输,但是对于i < j ...
- 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 ...
- 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 ...
随机推荐
- 遮盖层实现(jQuery+css+html)
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- pip 安装 lxml等 出错 解决
x86-gnu-gcc 出错 安装如下 sudo apt-get install libffi-dev sudo apt-get install libssl-dev sudo apt-get ins ...
- MongoDB数据模型(一)
原文地址 一.数据模型介绍 MongoDB中的数据有着灵活的架构.与SQL数据库不同,因为SQL数据库必须先定义表结构,然后才能向其中插入数据,而MongoDB的集合不强制任何文档结构.这个灵活性方便 ...
- RocketMQ初步应用架构理论
RocketMQ初步应用架构理论 写给RocketMQ架构应用入门,内容涉及它的设计机理以及推到出来的应用注意事项,入门人员请看. 稍微涉及技术细节,留以我设计中间件时参考,将来整理深度文档时会抽取走 ...
- Redis持久存储-AOF&RDB
Redis中数据存储模式有2种:cache-only,persistence;cache-only即只做为"缓存"服务,不持久数据,数据在服务终止后将消失,此模式下也将不存在&qu ...
- 简单介绍移动端CSS3单位rem的用法
PC端大部份是用px单位,小部分用em单位,而移动端,请全部用rem单位吧.目前大部份设备,包括但不限于iOS 5+.Android 2.3+.Window Phone 8+都是可以兼容的,具体兼容表 ...
- 使用WTL的消息反射封装CEdit实现监听控件文本改变事件
消息反射机制可以使对消息的处理都集中在控件类中,以CEdit的EN_CHANGE消息为例: /*MyEdit.h*/ class CMyEdit:public CWindowImpl<CMyEd ...
- MySQL binlog 查看信息
1)按时间筛选 mysqlbinlog --start-datetime="2009-09-14 0:20:00" --stop-datetim="2009-09-15 ...
- xml 和json 数据格式及解析
来源:http://blog.jobbole.com/79252/ 引言 NOKIA 有句著名的广告语:“科技以人为本”.任何技术都是为了满足人的生产生活需要而产生的.具体到小小的一个手机,里面蕴含的 ...
- zonghe
package hcxAction; import hcxMode.Advertises; import hcxMode.Areas; import hcxMode.Saveresume; imp ...