杭电2851 简单dp
来源:互联网 发布:新浪微博刷活粉丝软件 编辑:程序博客网 时间:2024/06/03 08:02
这道题说白了就是一道水题,就是题意不太好理解。题意:给你多个区间,每个区间有一个危险值,接下来有多次询问,求从第一个区间到第n个区间的最小危险值。
就是一道简单的dp,题目:
Lode Runner
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 479 Accepted Submission(s): 224
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?
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.
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
310 41 4 75 6 33 7 52 9 810 13 812 14 1111 15 1316 18 517 19 68 20 9123105 51 4 53 6 105 8 202 9 17 10 2123454 41 5 12 7 202 7 37 9 41234
Sample Output
7-11224515356812148
#include <iostream>#include <cstdio>#include <string.h>#include <algorithm>#include <climits>using namespace std;struct road{ int beginpos; int endpos; int danlev;}ss[2012];int main(){//freopen("1.txt","r",stdin); int ncase,dp[2012];; scanf("%d",&ncase); while(ncase--){ int numroad,numask;memset(dp,0,sizeof(dp));scanf("%d%d",&numroad,&numask);for(int i=1;i<=numroad;++i)scanf("%d%d%d",&ss[i].beginpos,&ss[i].endpos,&ss[i].danlev);dp[1]=ss[1].danlev;for(int i=2;i<=numroad;++i){int min=INT_MAX;for(int j=1;j<i;++j){if(ss[i].beginpos<=ss[j].endpos&&dp[j]!=-1&&min>dp[j])min=dp[j];}if(min<INT_MAX) dp[i]=min+ss[i].danlev;elsedp[i]=-1;}int ask;while(numask--){ scanf("%d",&ask); //if(dp[ask]==0) // printf("-1\n"); //else printf("%d\n",dp[ask]);} } return 0;}
- 杭电2851 简单dp
- 杭电2151 简单DP
- 杭电1003(简单dp)
- 2084 杭电 数塔【简单dp】
- 杭电1003(大数)简单的DP简单过
- 杭电1235最少拦截系统(简单dp)
- DP 杭电2084
- 杭电5586(dp)
- 杭电2059 DP
- 杭电1158 DP
- 杭电1227 DP
- 杭电1203回溯+DP
- 杭电1257(DP)
- 杭电2571(DP)。
- 杭电2151 Worm dp
- 杭电简单计算器
- 杭电1719 简单数学题
- 杭电 1019 简单数学题
- SpringMVC
- find的一些使用
- 【个人笔记】基于AMF-RPC实现Flex与JAVA的交互实例【下】
- 短期记忆测试
- MFC之C++构造函数
- 杭电2851 简单dp
- 用户登录三次失败禁用2分钟
- Kconfig文档的作用
- C语言中常用库函数及其用法-sscanf()
- Android NDK的入门学习过程
- linux下的IPC机制之共享内存
- 内核的Makefile
- SQL字符类型小结
- javascript的复习