uva 10201

H - Adventures in Moving - Part IV

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit Status Practice UVA 10201

Description

Problem A: Adventures in Moving - Part IV

To help you move from Waterloo to the big city, you are considering renting a moving truck. Gas prices being so high these days, you want to know how much the gas for such a beast will set you back.

The truck consumes a full litre of gas for each kilometre it travels. It has a 200 litre gas tank. When you rent the truck in Waterloo, the tank is half full. When you return it in the big city, the tank must be at least half full, or you‘ll get gouged even more for gas by the rental company. You would like to spend as little as possible on gas, but you don‘t want to run out along the way.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

Input is all integers. The first integer is the distance in kilometres from Waterloo to the big city, at most 10000. Next comes a set of up to 100 gas station specifications, describing all the gas stations along your route, in non-decreasing order by distance. Each specification consists of the distance in kilometres of the gas station from Waterloo, and the price of a litre of gas at the gas station, in tenths of a cent, at most 2000.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

Output is the minimum amount of money that you can spend on gas to get you from Waterloo to the big city. If it is not possible to get from Waterloo to the big city subject to the constraints above, print "Impossible".

Sample Input

1

500
100 999
150 888
200 777
300 999
400 1009
450 1019
500 1399

Output for Sample Input

450550

dp[i][j]表示到达第i个加油站剩余油量为j时的最小花费

特殊地,dp[n][j]表示到达终点剩余油量为j时的最小花费

状态转移:(设w[i]为每个加油站的位置,p[i]为油单价)

行驶:dp[i][j-(w[i]-w[i-1])] = dp[i-1][j](0<i<=n)

加油:dp[i][j] = dp[i][j-1]+p[i](0<i<n)因为n是特意增加的终点,不是加油站

时间: 2024-07-30 01:26:59

uva 10201的相关文章

uva 10201 Adventures in Moving - Part IV (DP)

uva 10201 Adventures in Moving - Part IV 题目大意:借了一辆车,车里有100单位的油.要到达N米外的目的地(每走一米消耗一个单位的油),在这一段路程中,有若干个加油站,给出的数据是每个加油站的位置和加一单位油的价格.要求到达目的地且剩下100单位油的最小消费.(到达不了则输出Impossible) 解题思路:dp[i][j]数组代表的是第i个加油站油量为j的最小费用. 状态转移方程: dp[i][j]=min(dp[i][j],dp[i?1][j+(mil

UVA 10201 DP

Adventures in Moving - Part IV 题意: 汽车邮箱容量200升,最初有100升油,要求到达终点油箱中的油不少于100升的最小花费,不能到达终点输出Impossible. 汽车走1单位距离消耗1升油. 输入t组数据 输入n表示要求从起点到距离为n的点 输入若干个加油站的a,b,表示加油站距离起点的距离和每升油的价格: 代码: //dp[i][j]=min(dp[i][j],dp[i-1][j+dis-k]+k*w),dp[i][j]表示到达 //i加油站时还剩j升油,d

UVa 10201 Adventures in Moving - Part IV

https://vjudge.net/problem/UVA-10201 题意: 给出到达终点的距离和每个加油站的距离和油费,初始油箱里有100升油,计算到达终点时油箱内剩100升油所需的最少花费. 思路: 我们用d[i][j]来表示车子在第 i 个加油站时还剩 j 升油量的最小花费. 先说一下转移方程吧,d[i][j] = min(d[i][j], d[i - 1][j + l - k] + k*b[i]),k代表的是在 i 这个加油站所加的油量,加了之后的总油量就是 j . 需要注意的是,油

小白书关于动态规划

10192 最长公共子序列 http://uva.onlinejudge.org/index.php?option=com_onlinejudge& Itemid=8&page=show_problem&category=114&problem=1133&mosmsg= Submission+received+with+ID+13297616 */ #include <cstdio> #include <string.h> #include&

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B