HDU 2851.Lode Runner【DP动态规划】【5月11】


Lode Runner

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 796    Accepted Submission(s): 394


Problem Description
Lode Runner is a famous game, I think you played in your childhood.


Ok, now, I simple the problem. In the game, it has N horizontal roads, the ladders always stay at right side vertically, and the ladders are extending towards up and down with unlimited length. If ladder near or cross a road, little WisKey will walk on the road by climbed the ladder. Two roads were covered by each other in the X-axis; it will be considered can be passing through. Each road has an integer W means the dangerous level.

Little WisKey must start at No.1 road, and he can’t go back, he always go ahead. WisKey want to go some roads, so he needs to know how minimum sum of dangerous will happen. You can finish the game, yes?
 

Input
The first integer C represents the number of cases, And C cases followed.
  
Each test case contains a single integer N roads (1<=N<= 2000) and M destinations (1<=M<=500). The next N line contains three integers Si, Ei, Wi, meaning the road build from Si to Ei, and the Wi dangerous level (0 <= Si <= Ei <= 1000, 1 <= Wi <= 1000). And the roads sorted by Ei increasing yet. The last M line contains integers mean little WisKey’s destinations.
 

Output
  
For each questions, output the minimum sum of dangerous. If can’t reach the goal, please print -1.
 

Sample Input
  
  
3 10 4 1 4 7 5 6 3 3 7 5 2 9 8 10 13 8 12 14 11 11 15 13 16 18 5 17 19 6 8 20 9 1 2 3 10 5 5 1 4 5 3 6 10 5 8 20 2 9 1 7 10 2 1 2 3 4 5 4 4 1 5 1 2 7 20 2 7 3 7 9 4 1 2 3 4
 

Sample Output
  
  
7 -1 12 24 5 15 35 6 8 1 21 4 8
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAX = 2005;
int N, M, C, x, MIN;
struct ss
{
    int x, y, v;
    int dp;
}L[MAX];
int main()
{
    scanf("%d", &C);
    while(C--)
    {
        scanf("%d %d", &N, &M);
        scanf("%d %d %d", &L[0].x, &L[0].y, &L[0].v);
        L[0].dp = L[0].v;
        for(int i = 1;i < N; ++i)
        {
            MIN = INF;
            scanf("%d %d %d", &L[i].x, &L[i].y, &L[i].v);
            for(int j = 0;j < i; ++j)
            {
                if(L[j].y >= L[i].x && L[j].y <= L[i].y) MIN = min(MIN, L[j].dp+L[i].v);
            }
            L[i].dp = MIN;
        }
        while(M--)
        {
            scanf("%d", &x);
            if(L[x-1].dp == INF) cout << -1 << endl;
            else cout << L[x-1].dp << endl;
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值