Fixing the Great Wall
题意:
在一条线上,有n个坏的地方要修机器人修,机器人的移动速度V,若坏的地方立即被修花费ci,若没修,每单位时间增加d,出去机器人的开始位置,求修完n个地方的最小花费。
分析:
非常经典,求解“未来费用”的问题,考虑区间完成最后一定在区间边界上,才能保证最优。dp[i][j][k]表示修完区间长i起点为j的所有地点,k=0最后点在左边界,k=1最后点在右边界,花费最小的费用。现在考虑随着时间的花费增加的费用。时间*未走过的点的d之和为增加的费用。
dp[i][j][0]=min(dp[i-1][j+1][0]+费用,dp[i-1][j+1][1]+费用);
dp[i][j][1]=min(dp[i-1][j][0]+费用,dp[i-1][j][1]+费用);
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const double INF=1e22;
const int mod = ;
struct node{
int x,d,c;
}s[];
int sum[],sx,n;
double v;
double dp[][][];
bool cmp(node a,node b){
return a.x<b.x;
}
void solve(){
sum[]=;
for(int i=;i<=n;++i)
sum[i]=sum[i-]+s[i].d;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
{
dp[i][j][]=dp[i][j][]=INF;
}
for(int i=;i<=n;++i)
dp[][i][]=dp[][i][]=sum[n]*(abs(sx-s[i].x)/v)+s[i].c;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j){
int k=j+i-;
if(k>n)break;
dp[i][j][]=min(dp[i-][j+][]+((s[j+].x-s[j].x)/v)*(sum[j]+sum[n]-sum[k])+s[j].c,
dp[i-][j+][]+((s[k].x-s[j].x)/v)*(sum[j]+sum[n]-sum[k])+s[j].c);
dp[i][j][]=min(dp[i-][j][]+((s[k].x-s[j].x)/v)*(sum[j-]+sum[n]-sum[k-])+s[k].c,
dp[i-][j][]+((s[k].x-s[k-].x)/v)*(sum[j-]+sum[n]-sum[k-])+s[k].c);
}
printf("%.0lf\n",floor(min(dp[n][][],dp[n][][])));
}
int main()
{
while(~scanf("%d%lf%d",&n,&v,&sx)){
if(n==&&v==&&sx==)break;
for(int i=;i<=n;++i)
scanf("%d%d%d",&s[i].x,&s[i].c,&s[i].d);
sort(s+,s+n+,cmp);
solve();
}
return ;
}
Fixing the Great Wall的更多相关文章
- 【暑假】[深入动态规划]UVa 10618 Fixing the Great Wall
UVa 10618 Fixing the Great Wall 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=361 ...
- UVA-1336 Fixing the Great Wall(区间DP)
题目大意:长城(视作x正半轴)有n处破损.有一个智能修复机器人,它的初始位置和移动速度已知.每处破损处都有一组参数(x,c,d),x表示位置,c.d表示在时间t后再修复该处破损的花费为d*t+c.求用 ...
- 【杂题总汇】UVa-1336 Fixing the Great Wall
[UVA-1336]Fixing the Great Wall 一开始把题看错了……直接用的整数存储答案:之后用double存最后输出答案的时候取整就AC了
- UVa 1336 Fixing the Great Wall (区间DP)
题意:给定 n 个结点,表示要修复的点,然后机器人每秒以 v 的速度移动,初始位置在 x,然后修复结点时不花费时间,但是如果有的结点暂时没修复, 那么每秒它的费用都会增加 d,修复要花费 c,坐标是 ...
- uva1336 Fixing the Great Wall
用到了kase避免memset超时 #include<cstdio> #include<cstring> #include<cmath> #include<a ...
- 【Uva 1336】Fixing the Great Wall
[Link]: [Description] 给你长城上的n个修补点,然后你的位置为x; 你需要依次去这n个点,然后把它们全部修好. 但是修的前后顺序不一样的话,花费不一样. 如果立即把第i个点修好的话 ...
- [SinGuLaRiTy] 动态规划题目复习
[SinGuLaRiTy-1026] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [UVA 1025] A Spy in the Metr ...
- 2021record
2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...
- [poj1113][Wall] (水平序+graham算法 求凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
随机推荐
- Java学习笔记(一) java介绍
编程语言分为:编译型语言和解释型语言. 编译型语言需要经过特定编译器通过一次性编译,成为该特定平台硬件可执行的机器码,可脱离开发环境独立运行,运行效率较高,但是无法跨平台移植. 解释型语言需要经过特定 ...
- *[hackerrank]Sam and sub-strings
https://www.hackerrank.com/contests/w3/challenges/sam-and-substrings DP.注意到以N[i]结尾的每个字符串的子数字和有规律: 53 ...
- nginx的location配置
http://blog.sina.com.cn/s/blog_97688f8e0100zws5.html http://blog.csdn.net/yanook/article/details/100 ...
- struts1,struts2,springMVC终极对比
最近做项目用到了struts2,之前一直是用struts1和springMVC.感觉到了struts2从很大程度上和这两个还是有很大区别的,所以今天搜集了些资料,给他们做一下对比. Struts1官方 ...
- OracleApps Dropship 流程
做的一个Dropship流程的实录(包括流程期间遇到问题的解决)What are the advantages of Drop Shipment Orders?These are the benefi ...
- 迷宫问题(bfs的应用)
问题描述: 定义一个二维数组N*M(其中2<=N<=10;2<=M<=10),如5 × 5数组下所示: int maze[5][5] = { 0, 1, 0, 0, 0, 0, ...
- Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum
题目链接 题意:一个m个面的骰子,抛掷n次,求这n次里最大值的期望是多少.(看样例就知道) 分析: m个面抛n次的总的情况是m^n, 开始m==1时,只有一种 现在增加m = 2, 则这些情况是新增 ...
- 一台电脑同时运行多个tomcat配置方法
当第一个tomcat启动后,后面tomcat的server.xml中的端口不管怎么改,仍然会报端口冲突.后来在dos下运行才发现所有的tomcat都会去找CATALINA_HOME和CATALINA_ ...
- Struts2系列——struts2的result
在action的指定方法执行完毕后总会返回一个字符串,struts2根据返回的字符串去action的配置中的result去找匹配的名字,根据配置执行下一步的操作. 在ActionSupport基类中定 ...
- SharePoint的安装配置
安装环境 1. Window server 2008 r2(sp2) OS.2. MS SQL Server 2008 r2.3. Office2010.4. IIS7以上.5. 确认服务器已经加入域 ...