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 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.
Input
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.
Output
Print the maximum total number of produced goods that can be sold in all cities after a sequence of transportations.
Sample Input
3 0
1 2 3
3 2 1
Sample Output
4
Hint
题意
给你n个城市,每个城市都可以往编号比自己大的城市运送c容量为物品
每个城市可以生产最多p[i]物品,最多售卖s[i]物品
然后问你这n个物品,最多卖多少物品,一共。
题解:
如果数据范围小的话,那么显然是网络流,直接莽一波就好了
但是这个过不了。
考虑最大流等于最小割,我们可以考虑dp[i][j]表示考虑i个点,我们割掉了j个汇点的最小花费。
那么这个dp[i][j]=min(dp[i-1][j-1]+s[i],dp[i-1][j]+p[i]+cj)
然后滚动数组优化一下就好了
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n;
long long c,p[maxn],s[maxn],f[maxn],ans,sum;
int main()
{
cin>>n>>c;
for(int i=1;i<=n;i++)cin>>p[i];
for(int i=1;i<=n;i++)cin>>s[i];
for(int i=1;i<=n;i++){
f[i]=1e18;
for(int j=i;j>=1;j--)
f[j]=min(f[j]+j*c+p[i],f[j-1]+s[i]);
f[0]+=p[i];
}
ans=1e18;
for(int i=0;i<=n;i++)
ans=min(ans,f[i]);
cout<<ans<<endl;
}
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation 动态规划的更多相关文章
- CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort 暴力枚举,水 1.题意:n*m的数组, ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)D Dense Subsequence
传送门:D Dense Subsequence 题意:输入一个m,然后输入一个字符串,从字符串中取出一些字符组成一个串,要求满足:在任意长度为m的区间内都至少有一个字符被取到,找出所有可能性中字典序最 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort
链接 题意:输入n,m,表示一个n行m列的矩阵,每一行数字都是1-m,顺序可能是乱的,每一行可以交换任意2个数的位置,并且可以交换任意2列的所有数 问是否可以使每一行严格递增 思路:暴力枚举所有可能的 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing
我不告诉你这个链接是什么 分析:模拟可以过,但是好烦啊..不会写.还有一个扩展欧几里得的方法,见下: 假设光线没有反射,而是对应的感应器镜面对称了一下的话 左下角红色的地方是原始的的方格,剩下的三个格 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)
http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...
- 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 Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)
传送门 Description You are given names of two days of the week. Please, determine whether it is possibl ...
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort(暴力)
传送门 Description You are given a table consisting of n rows and m columns. Numbers in each row form a ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B
Description You are given a table consisting of n rows and m columns. Numbers in each row form a per ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A
Description You are given names of two days of the week. Please, determine whether it is possible th ...
随机推荐
- bzoj千题计划179:bzoj1237: [SCOI2008]配对
http://www.lydsy.com/JudgeOnline/problem.php?id=1237 如果没有相同的数不能配对的限制 那就是排好序后 Σ abs(ai-bi) 相同的数不能配对 交 ...
- 原生JS 基础总结
0. 好习惯 分号 ; 花括号 {}, var 弄清楚 null , undefined 区别 , isNaN, === 与 == 区别 1. prompt , confirm , alert 不同框 ...
- 【原创】when.js2.7.1源码解析
现在,用回调处理一些复杂的逻辑,显得代码臃肿,难于阅读,特别是异步,嵌套. 解决这样的问题,可以是之前所说的Backbone.Events的pubsub,或者是今天要说的when.js所实现的prom ...
- argunlar 1.0.0 【hello,world】
<!DOCTYPE html><html lang="en" ng-app><head> <meta charset="U ...
- Python3之外部文件调用Django程序操作model等文件实现
import os import sys import django sys.path.append(r'C:\Users\Administrator\PycharmProjects\your pro ...
- Oracle错误及解决方案
1.ORA-00257:归档程序错误.在释放之前仅限于内部链接 问题原因:归档日志占满了空间 解决方法: .增加归档日志空间 alter system set db_recovery_file_des ...
- LeetCode(21):合并两个有序链表
Easy! 题目描述: 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1->3->4 输出:1- ...
- Java 日期时间获取和显示
Java正确获取星期Calendar.DAY_OF_WEEKhttp://chamcon.iteye.com/blog/2144433 Java SimpleDateFormat 中英文时间格式化转换 ...
- 使用 JavaScript 编写优化算法 (1)
之前一直用Python来写优化算法,为了增强 JS 的熟练程度,开始将原有的代码改写成 JS.采用的工具包括 node.js + Grunt + nodeunit + github + npm + t ...
- ORM,DAO,MVC,POJO
1.ORM 对象关系映射(Object Relational Mapping,简称ORM)是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. 简单的说,ORM是通过使用描述对象和数据库之间 ...