【HDOJ】2851 Lode Runner

时间:2024-01-02 10:23:15

开始没理解题意。原来destinations是指路的序号。而不是点。DP。

 #include <stdio.h>
#include <string.h> int dp[]; typedef struct {
int s, e, w;
} road_st; road_st roads[]; int main() {
int case_n;
int n, m, des;
int i, j, min; scanf("%d", &case_n); while (case_n--) {
scanf("%d%d", &n, &m);
for (i=; i<=n; ++i)
scanf("%d%d%d", &roads[i].s, &roads[i].e, &roads[i].w);
memset(dp, , sizeof(dp));
dp[] = roads[].w;
for (i=; i<=n; ++i) {
min = 0x7fffffff;
for (j=; j<i; ++j) {
if (roads[i].s <= roads[j].e && dp[j]!=- && dp[j]<min)
min = dp[j];
}
if (min < 0x7fffffff)
dp[i] = min + roads[i].w;
else
dp[i] = -;
}
for (i=; i<m; ++i) {
scanf("%d", &des);
printf("%d\n", dp[des]);
}
} return ;
}