用到了kase避免memset超时

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cassert>
using namespace std; const int maxn = + ;
const double INF = 1e30; struct Section {
double x, c, dt;
bool operator < (const Section& rhs) const {
return x < rhs.x;
}
} s[maxn]; int kase, n;
int vis[maxn][maxn][];
double v, x, d[maxn][maxn][];
double psdt[maxn]; // prefix sum of dt // cost accumulated when walking from x1 and x2.
// section[i~j] are already finished
double cost(double x1, double x2, int i, int j) {
double finished_dt = ;
assert(i <= j);//not necessary
if(i >= && j >= ) finished_dt += psdt[j] - psdt[i-]; // -1 -1�����
return (psdt[n] - finished_dt) * fabs(x2 - x1) / v;
} double dp(int i, int j, int p) { //p=0��ǰ��i,p=1��ǰ��j
if(i == && j == n) return ;
double& ans = d[i][j][p];
if(vis[i][j][p] == kase) return ans;
vis[i][j][p] = kase; ans=INF;
double x = (p == ? s[i].x : s[j].x);
if(i > ) ans = min(ans, dp(i-, j, ) + cost(x, s[i-].x, i, j));
if(j < n) ans = min(ans, dp(i, j+, ) + cost(x, s[j+].x, i, j));
return ans;
} int main() {
memset(vis, , sizeof(vis));
while(scanf("%d%lf%lf", &n, &v, &x) == && n) {
kase++;
double sumc = ;
for(int i = ; i <= n; i++) {
scanf("%lf%lf%lf", &s[i].x, &s[i].c, &s[i].dt);
sumc += s[i].c;
}
sort(s+, s+n+); psdt[] = ;
for(int i = ; i <= n; i++)
psdt[i] = psdt[i-] + s[i].dt; s[].x = -INF;
s[n+].x = INF;
double ans = INF;
for(int i = ; i <= n+; i++)
if(x > s[i-].x && x < s[i].x) {
if(i > )
ans = min(ans, dp(i-, i-, ) + cost(x, s[i-].x, -, -)); // move left
if(i <= n)
ans = min(ans, dp(i, i, ) + cost(x, s[i].x, -, -)); // move right
break;
}
printf("%.0lf\n", floor(ans + sumc));
}
return ;
}

uva1336 Fixing the Great Wall的更多相关文章

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

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

  2. 【杂题总汇】UVa-1336 Fixing the Great Wall

    [UVA-1336]Fixing the Great Wall 一开始把题看错了……直接用的整数存储答案:之后用double存最后输出答案的时候取整就AC了

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

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

  4. Fixing the Great Wall

    题意: 在一条线上,有n个坏的地方要修机器人修,机器人的移动速度V,若坏的地方立即被修花费ci,若没修,每单位时间增加d,出去机器人的开始位置,求修完n个地方的最小花费. 分析: 非常经典,求解“未来 ...

  5. UVa 1336 Fixing the Great Wall (区间DP)

    题意:给定 n 个结点,表示要修复的点,然后机器人每秒以 v 的速度移动,初始位置在 x,然后修复结点时不花费时间,但是如果有的结点暂时没修复, 那么每秒它的费用都会增加 d,修复要花费 c,坐标是 ...

  6. 【Uva 1336】Fixing the Great Wall

    [Link]: [Description] 给你长城上的n个修补点,然后你的位置为x; 你需要依次去这n个点,然后把它们全部修好. 但是修的前后顺序不一样的话,花费不一样. 如果立即把第i个点修好的话 ...

  7. 2021record

    2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...

  8. [SinGuLaRiTy] 动态规划题目复习

    [SinGuLaRiTy-1026] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [UVA 1025] A Spy in the Metr ...

  9. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

随机推荐

  1. 在msys里进行复制和粘贴操作

    You can copy text from an MSYS window to the clipboard simply by selecting the text you want to copy ...

  2. java利用Aspose.words.jar将本地word文档转化成pdf(完美破解版 无水印 无中文乱码)

    package doc; import java.io.*; import junit.framework.Test; import com.aspose.words.*; public class ...

  3. BZOJ[4127] Abs

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=4127 不算难的样子,才见过此类模型. 首先可以发现每次修改只增不减,那么这$O(n)$的负数最 ...

  4. Naïve Bayes Models

    贝叶斯模型假设: 为防止概率为零的情况,做拉普拉斯平滑得: 下面介绍一下朴素贝叶斯模型与多变量伯努利模型的区别: 朴素贝叶斯: 多变量伯努利: 即: 多变量伯努利模型不考虑样本出现的次数,每个特征的取 ...

  5. POJ 3419 Difference Is Beautiful (DP + 二分 + rmq)

    题意:给n个数(n<=200000),每个数的绝对值不超过(10^6),有m个查询(m<=200000),每次查询区间[a,b]中连续的没有相同数的的最大长度. 析:由于n太大,无法暴力, ...

  6. jqGrid 编辑完数据后能返回到当前位置的方法

    jqGrid 是一个js的jquery组件,虽然不轻便,但功能还是蛮强大的,也比较方便使用.在数据加载后,经常需要对其中的记录进行编辑,修改完后再返回时需要看到修改后的数据,一般采取重新加载的方法re ...

  7. 在 DotNetty 中实现同步请求

    一.背景 DotNetty 本身是一个优秀的网络通讯框架,不过它是基于异步事件驱动来处理另一端的响应,需要在单独的 Handler 去处理相应的返回结果.而在我们的实际使用当中,尤其是 客户端程序 基 ...

  8. 51nod1266【水】

    最短,两半分开走 最长,一边走,比较一下两端就好了. #include <bits/stdc++.h> using namespace std; typedef long long LL; ...

  9. hdu 1521 排列组合【指数型生成函数】

    根据套路列出式子:\( \prod_{i=1}^{n}\sum_{j=0}^{c[i]}\frac{x^j}{j!} \),然后暴力展开即可 #include<iostream> #inc ...

  10. bzoj 4446: [Scoi2015]小凸玩密室【树形dp】

    神仙题!参考https://www.cnblogs.com/wfj2048/p/7695711.html 注意完全二叉树不是满二叉树!!!! 设g[u][j]为u遍历完子树到深度为i-1的祖先的兄弟的 ...