题意:给定 n 个结点,表示要修复的点,然后机器人每秒以 v 的速度移动,初始位置在 x,然后修复结点时不花费时间,但是如果有的结点暂时没修复,

那么每秒它的费用都会增加 d,修复要花费 c,坐标是 pos,问你最少花费是多少。

析:dp[i][j][k] 表示已经修复了 i-j 区间,并且当前在 k,那么两种方案,向左移动,或者向右移动,最后输出就好了。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define print(a) printf("%d\n", (a))
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Node{
int pos, cost, det;
bool operator < (const Node &p) const{
return pos < p.pos;
}
};
Node a[maxn];
double sum[maxn], v;
double dp[maxn][maxn][2]; double cal(int i, int j, int l, int r){
double t = 1.0 * fabs(a[l].pos-a[r].pos) / v;
double ans = sum[i-1] + sum[n+1] - sum[j];
return ans * t;
} int solve(){
for(int i = 0; i <= n+1; ++i)
for(int j = 0; j <= n+1; ++j)
dp[i][j][0] = dp[i][j][1] = inf; int p = lower_bound(a+1, a+n+1, (Node){m, 0, 0}) - a;
dp[p][p][0] = dp[p][p][1] = 0.0; for(int i = p; i > 0; --i){
for(int j = p; j <= n+1; ++j){
dp[i-1][j][0] = min(dp[i-1][j][0], dp[i][j][0]+cal(i, j, i, i-1)+a[i-1].cost);
dp[i-1][j][0] = min(dp[i-1][j][0], dp[i][j][1]+cal(i, j, j, i-1)+a[i-1].cost);
dp[i][j+1][1] = min(dp[i][j+1][1], dp[i][j][0]+cal(i, j, i, j+1)+a[j+1].cost);
dp[i][j+1][1] = min(dp[i][j+1][1], dp[i][j][1]+cal(i, j, j, j+1)+a[j+1].cost);
}
}
return min(dp[1][n+1][0], dp[1][n+1][1]);
} int main(){
while(scanf("%d %lf %d", &n, &v, &m) == 3 && n+v+m){
for(int i = 1; i <= n; ++i) scanf("%d %d %d", &a[i].pos, &a[i].cost, &a[i].det);
a[n+1].pos = m; a[n+1].cost = a[n+1].det = 0;
sort(a+1, a+n+2);
sum[0] = 0;
for(int i = 1; i <= n+1; ++i) sum[i] = sum[i-1] + a[i].det; int ans = solve();
printf("%d\n", ans);
}
return 0;
}

UVa 1336 Fixing the Great Wall (区间DP)的更多相关文章

  1. 【暑假】[深入动态规划]UVa 10618 Fixing the Great Wall

    UVa 10618 Fixing the Great Wall 题目:  http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=361 ...

  2. UVA 10529 - Dumb Bones(概率+区间dp)

    UVA 10529 - Dumb Bones option=com_onlinejudge&Itemid=8&category=518&page=show_problem&am ...

  3. uva 10304 - Optimal Binary Search Tree 区间dp

    题目链接 给n个数, 这n个数的值是从小到大的, 给出个n个数的出现次数. 然后用他们组成一个bst.访问每一个数的代价是这个点的深度*这个点访问的次数. 问你代价最小值是多少. 区间dp的时候, 如 ...

  4. UVA 10891 Game of Sum(区间DP(记忆化搜索))

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  5. uva 10453 【回文串区间dp】

    Uva 10453 题意:给定字符串,问最少插入多少个字符使其变成回文串,并任意输出一种结果. 题解:和Uva 10739类似,这里是只能增加.类似定义dp[i][j]表示子串Si...Sj变为回文串 ...

  6. UVA - 10891 Game of Sum (区间dp)

    题意:AB两人分别拿一列n个数字,只能从左端或右端拿,不能同时从两端拿,可拿一个或多个,问在两人尽可能多拿的情况下,A最多比B多拿多少. 分析: 1.枚举先手拿的分界线,要么从左端拿,要么从右端拿,比 ...

  7. UVA 1626 区间dp、打印路径

    uva 紫书例题,这个区间dp最容易错的应该是(S)这种匹配情况,如果不是题目中给了提示我就忽略了,只想着左右分割忘记了这种特殊的例子. dp[i][j]=MIN{dp[i+1][j-1] | if( ...

  8. UVA-1336 Fixing the Great Wall(区间DP)

    题目大意:长城(视作x正半轴)有n处破损.有一个智能修复机器人,它的初始位置和移动速度已知.每处破损处都有一组参数(x,c,d),x表示位置,c.d表示在时间t后再修复该处破损的花费为d*t+c.求用 ...

  9. BZOJ 1260&UVa 4394 区间DP

    题意: 给一段字符串成段染色,问染成目标串最少次数. SOL: 区间DP... DP[i][j]表示从i染到j最小代价 转移:dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k ...

随机推荐

  1. python各种类型转换

    python各种类型转换 学习了:https://blog.csdn.net/shanliangliuxing/article/details/7920400 https://blog.csdn.ne ...

  2. 锤子Smartisan T1手机官方4.4.2系统内核版本号信息

    从锤子smartisan T1手机官方系统EGL中获取内核版本号信息(由cofface提供): I/Adreno-EGL(  816): <qeglDrvAPI_eglInitialize:41 ...

  3. HTML--比较实用的小例子

    常用的前端实例: 1略 2.在网页商城中的图片当我们把鼠标放上去之后,图片会显示一个有颜色的外边框,图片某一部分的字体的颜色并发生改变 鼠标放上去之前 鼠标放上去之后: 实现的代码: <!DOC ...

  4. Spark MLlib Deep Learning Convolution Neural Network (深度学习-卷积神经网络)3.2

    3.Spark MLlib Deep Learning Convolution Neural Network(深度学习-卷积神经网络)3.2 http://blog.csdn.net/sunbow0 ...

  5. NSArray中存的是实体时的排序

    NSArray中存储的是实体时的排序 by 伍雪颖 NSSortDescriptor *sortDescriptor1 = [NSSortDescriptor sortDescriptorWithKe ...

  6. 嵌入式学习笔记(综合提高篇 第一章) -- 利用串口点亮/关闭LED灯

    1      前言 从踏入嵌入式行业到现在已经过去了4年多,参与开发过的产品不少,有交换机.光端机以及光纤收发器,停车场出入缴费系统,二维码扫码枪,智能指纹锁以及数字IC芯片开发等; 涉及产品中中既有 ...

  7. PHP读取excel(6)

    有时候我们只需要读取某些指定sheet,具体代码如下: <?php header("Content-Type:text/html;charset=utf-8"); //引入读 ...

  8. [LeetCode] 038. Count and Say (Easy) (C++/Python)

    索引:[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 038. Cou ...

  9. android-auto-scroll-view-pager

    https://github.com/eltld/android-auto-scroll-view-pager

  10. Linux安装配置Redis CentOS 7 下安装Redis

    Redis是一个高性能的,开源key-value型数据库.是构建高性能,可扩展的Web应用的完美解决方案,可以内存存储亦可持久化存储.因为要使用跨进程,跨服务级别的数据缓存,在对比多个方案后,决定使用 ...