UVA - 10201 Adventures in Moving - Part IV
来源:互联网 发布:java 多重循环 break 编辑:程序博客网 时间:2024/05/29 14:46
题目大意:有n个测试数据组, 对于每个测试组,最先给出一个距离lenth, 然后给出若干个加油站的位置以及加油站每升油的价钱。然后有量油桶容量为200升的卡车,出距离为0的位置开始移动向lenth,每升油可以使的卡车走一个单位距离,问,卡车到达lenth的时候,并且油箱中仍有100升油,最少花费多少钱,如果不能到达,输出“Impossible”。
解题思路:用递推的方法,对每个加油站进行处理,dp[i][j],i代表第i个加油站,j表示油箱有多少升油。j的范围为0~200。然后除了起点之外,其他的油箱最大值为200,如果s[i].dis - s[i - 1].dis > top, 说明在中间的路程会出现断油,到达不了终点,并且dp[i][j]的最小值有两种来源,一种是从前一个加油站剩余的油,另一种是在本站加油。
<span style="font-size:18px;">#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main() {int T, end, DP[105][205], D[105] = {0}, P[105] = {0};scanf("%d%*C",&T);while(T--) {scanf("%d%*C", &end); int n = 1;char line[50];while(gets(line) && line[0]) {sscanf(line,"%d%d", &D[n], &P[n]);if (D[n] > end) break;n++;}D[n] = end;memset(DP, 0x3f3f3f3f, sizeof(DP));DP[0][100] = 0;for(int i = 1; i <= n; i++) {int dis = D[i] - D[i-1];for(int j = dis; j <= 200; j++)DP[i][j-dis] = DP[i-1][j];if (i == n) break;for(int j = 1; j <= 200; j++) {DP[i][j] = min(DP[i][j], DP[i][j-1] + P[i]);}}if (DP[n][100] != 0x3f3f3f3f)printf("%d\n", DP[n][100]);elseprintf("Impossible\n");if (T) printf("\n");}return 0;}</span>
0 0
- uva 10201 Adventures in Moving - Part IV
- UVA 10201 Adventures in Moving - Part IV
- UVA 10201 Adventures in Moving - Part IV
- UVA 10201 Adventures in Moving - Part IV
- uva 10201 Adventures in Moving - Part IV
- UVA - 10201 Adventures in Moving - Part IV
- uva 10201 - Adventures in Moving - Part IV
- UVA - 10201 Adventures in Moving - Part IV
- UVA - 10201 Adventures in Moving - Part IV
- UVA - 10201 Adventures in Moving - Part IV
- uva 10201 Adventures in Moving - Part IV
- uva--UVA 10201Adventures in Moving - Part IV
- Adventures in Moving - Part IV+uva+dp
- UVA 10201 Adventures in Moving - Part IV(dp)
- uva 10201 - Adventures in Moving - Part IV(dp)
- UVA 10201 Adventures in Moving - Part IV 车站加油 dp
- Adventures in Moving - Part IV - UVa 10201 dp
- UVA 10201 Adventures in Moving - Part IV(动态规划)
- 面试准备
- 多线程信号
- 【C++】步步为营之知识点积累
- 深搜解Riding the Fences
- delphi android 我来了
- UVA - 10201 Adventures in Moving - Part IV
- [ldd]Linux使用ldd命令查看程序调用了哪些动态库
- Android线性布局LinearLayout(七)
- 【排序算法】冒泡排序
- Android学习笔记の四
- UVA - 10453 Make Palindrome
- Topcoder
- 引导页的介绍
- 静态库和动态库