题意:给定 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. win7安装ANT

    点击进入ant官网,找到下载选项.   选择下载安装文件.其余的源文件和手册的下载步骤完全相同.   可以下载官网上对应系统的最新版本.也可以在old ant 版本中选择自己需要的版本.笔者需要ant ...

  2. 2015 Multi-University Training Contest 3--1011 Work

    代码: #include<cstdio> #include<cstring> using namespace std; int n,k; int father[105],son ...

  3. Screen 状态栏配置

    http://havee.me/linux/2010-08/screen-status-bar.html Screen 状态栏配置 GNU 的 screen 是一个很好的工具.如果需要经常或者大量的登 ...

  4. Creo二次开发--内存清理函数

    我们在处理模型文件时,总会遇到内存环境的清除问题.一个干净的Creo工作环境.是保证工作能顺利完毕的保障. ProMdlEraseNotDisplayed()函数提供了清除未显示模型的功能. 当须要循 ...

  5. openwrt mt7620 内存大小检测

    单独编译内核: make V=s target/linux/install 相调函数调用流程: init/main.c : start_kernel() -> setup_arch(&c ...

  6. JOIN ,LEFT JOIN ,ALL JOIN 等的区别和联系

    left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录  right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录 inner join(等值连接) ...

  7. MYSQL使用inner join 进行 查询/删除/修改示例

    代码如下: --查询 SELECT tp.tp_id, tp.tpmc, tp.leveid, tp.tpdz, tp.jgm, tp.scsj, tp.pbzyid, tp.ksbfsj, tp.j ...

  8. atitit.eclipse有多少api&#160;&#160;扩展点,以及扩展点的设计

    atitit.eclipse有多少api  扩展点,以及扩展点的设计 不赞成使用的.作废的以及内部的扩展点 [扩展]页显示了几个你不应该在你的插件中使用的扩展点.在附表C.1的[描写叙述]栏中.我们使 ...

  9. HDU 6073 Matching In Multiplication dfs遍历环 + 拓扑

    Matching In Multiplication Problem DescriptionIn the mathematical discipline of graph theory, a bipa ...

  10. LiberOJ #6210. 「美团 CodeM 决赛」tree 树形DP

    题目链接:点这里 题解: 需要证明,所求的路径一定是全部权值都为1或者,路径上权值至多有一个为2其余为1且权值2在路径中央. 然后树形DP 设定dp[i][0/1] 以1为根的情况下,以i 节点下子树 ...