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 ...
随机推荐
- Spark开发指南
原文链接http://www.sxt.cn/info-2730-u-756.html 目录 Spark开发指南 简介 接入Spark Java 初始化Spark Java 弹性分布式数据集 并行集合 ...
- 如何提升 CSS 选择器性能
CSS 选择器性能损耗来自? CSS选择器对性能的影响源于浏览器匹配选择器和文档元素时所消耗的时间,所以优化选择器的原则是应尽量避免使用消耗更多匹配时间的选择器.而在这之前我们需要了解CSS选择器匹配 ...
- messagebox在最顶层写法
MessageBox(Application.Handle, 'text', 'caption', MB_TOPMOST + MB_ICONINFORMATION);) 或者 MessageBox(S ...
- SignalR的坑爹细节
好吧!SignalR的确是好用,照着官网的例子自己敲了一遍,死活得不到效果... 检查了半天,抱着试一试的心态吧原来在服务端大写开头的Hub类和大写开头的方法在客户端调用的时候,全部改成小写,一刷新, ...
- 大数据加减(Big data addition and subtraction)
题目描述 Description 加减法是计算中的基础运算,虽然规则简单,但是位数太多了,也难免会出错.现在的问题是:给定任意位数(不超过1000位)的加减法算式,请给出正确结果.为提高速度,保证给定 ...
- ubuntu切换到超级管理员权限
默认情况下是无法切换的,需要给root用户设置上密码 mars@mars-LIFEBOOK-LH531:~$ sudo passwd root[sudo] password for mars: 输入新 ...
- java集合概念
Collection(单列集合) List(有序,可重复) ArrayList 底层数据结构是数组,查询快,增删慢 线程不安全,效率高 Vector 底层数据结构是数组,查询快,增删慢 线程安全,效率 ...
- libPods.a 无法找到的解决方法
http://stackoverflow.com/questions/9863836/library-not-found-for-lpods To be clear for newbies out t ...
- stm32时钟配置总结
stm32时钟配置时钟源: 1,HSE(高速外部时钟)即常见的外接8M晶振方案: 2,HSI(高速内部时钟) 即8M内部振荡时钟方案: 3,LSE(低速外部时钟)即常见的32.768Khz晶振方案: ...
- oracle创建数据库表空间
1.创建表空间(存放数据) create tablespace xtba_datadatafile 'F:\ORACLE\ORADATA\ORCL\XTBA.DBF'size 50mautoexten ...