uva10201 - Adventures in Moving - Part IV

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

Problem A: Adventures in Moving - Part IV

To help you move from Waterloo to the big city, you are consideringrenting a moving truck. Gas prices being so high these days, you want toknow 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. Ithas a 200 litre gas tank. When you rent the truck in Waterloo, the tankis half full. When you return it in the big city, the tank must be atleast half full, or you'll get gouged even more for gas by the rentalcompany. You would like to spend as little as possible on gas, but youdon'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 kilometresfrom Waterloo to the big city, at most 10000. Next comes a set of up to100 gas station specifications, describing all the gas stations alongyour route, in non-decreasing order by distance. Each specification consists of the distance in kilometres ofthe gas station from Waterloo, and the price of a litre of gas at thegas 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 getyou from Waterloo to the big city. If it is not possible to get fromWaterloo 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

 

  车要从起点到终点,油气罐容量200,一开始有100的油,升序给出各个加油站离起点的位置和这个加油站加每单位油的价格,到终点的油至少要100,问最少花多少钱。

  开始想的是dp[i][j]是距离为i油为j的最少钱,其实这样就有很多不必要的计算,在各个地方的最优值就是它最近的上一个加油站的最优值加上之间的距离(如果可能),所以只要用dp[i][j]表示第i个加油站油量为j的最优值。状态转移方程有点难想。

 

#include<cstring>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
int a[110],b[110];
int dp[10010][210];
int main(){
   freopen("in.txt","r",stdin);
    int T,N,K;
    scanf("%d",&T);
    char s[100];
    while(T--){
        scanf("%d",&N);
        getchar();
        K=1;
        int i,j,k;
        while(gets(s)!=NULL&&s[0]!=0){
            sscanf(s,"%d%d",&a[K],&b[K]);
            K++;
        }
        memset(dp,INF,sizeof(dp));
        a[0]=0;
        dp[0][100]=0;
        for(i=1;i<K;i++)
        for(j=0;j<=200;j++){
            if(j+a[i]-a[i-1]<=200) dp[i][j]=dp[i-1][j+a[i]-a[i-1]];
            for(k=0;k<j;k++) dp[i][j]=min(dp[i][j],dp[i][k]+(j-k)*b[i]);
        }
        if(dp[K-1][100+N-a[K-1]]!=INF) printf("%d\n",dp[K-1][100+N-a[K-1]]);
        else printf("Impossible\n");
        if(T) puts("");
    }
    return 0;
}



uva 10201 Adventures in Moving - Part IV uva 10201 阅读详情

相关推荐

Uva--10201(动规)

2014-08-0500:14:22 2014-08-0500:02:00 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 s...

dingdi3021的博客 172

UVa 10201 Adventures in Moving - Part IV / 恶心的DP!!!伤不起

不会做DP的孩子伤不起 dp[i][j]表示到第i个站剩下油j的最小花费 油最满200 起点0 有100升 到终点是至少要留下100升 写了三个for 可以优化到2个for 没能力 以后有空在优 话说UVa的题目越做越难了 伤不起 #include #include #include using namespace std; const int maxn = 210; int

嗯。 1170

uva_10201 - Adventures in Moving - Part IV (普通DP)

这个题目,感觉描述不完整,不多说了,勉强Ac 状态: dp[i][j] 表示在第i个加油站中还有j升油的最小花费 状态转移: dp[i][j] = min(dp[i-1][k+dist[i-1,i]], dp[i][k-x]+cost(x)) #include #include #include using namespace std; #define PRICE 0

unixcsir的专栏 344

Adventures in Moving - Part IV+uva+dp

Adventures in Moving - Part IV Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Description Problem A: Adventures in Moving - Part IV T

u012870383的专栏 606

uva 10201 - Adventures in Moving - Part IV(dp)

题目链接:10201 - Adventures in Moving - Part IV 题目大意:有n个测试数据组, 对于每个测试组,最先给出一个距离lenth, 然后给出若干个加油站的位置以及加油站每升油的价钱。然后有量油桶容量为200升的卡车,出距离为0的位置开始移动向lenth,每升油可以使的卡车走一个单位距离,问,卡车到达lenth的时候,并且油箱中仍有100升油,最少花费多少钱

不慌不忙、不急不躁 1774

UVA 10201 Adventures in Moving - Part IV 车站加油 dp

题意:一辆车要求到达指定远的目标地点,一路上又一些加油站,给出加油站的位置和价格,出发时车100L汽油,要求到达目的地点也要有100L汽油。 这道题做了好久,dp[i][j]表示在第i站还有j升油的花费,状态转移是在第i站加油或不加,不加油就是上一站的对应汽油时的花费,加油的话就是min(dp[i][j], dp[i - 1][j - k + d[i] - d[i - 1]] + k * p[i

水果君の日常 1766

UVA - 10201 Adventures in Moving - Part IV

题目大意:有n个测试数据组, 对于每个测试组,最先给出一个距离lenth, 然后给出若干个加油站的位置以及加油站每升油的价钱。然后有量油桶容量为200升的卡车,出距离为0的位置开始移动向lenth,每升油可以使的卡车走一个单位距离,问,卡车到达lenth的时候,并且油箱中仍有100升油,最少花费多少钱,如果不能到达,输出“Impossible”。 解题思路:用递推的方法,对每个加油站进行

Bingo 1718

uva10201 - Adventures in Moving - Part IV(01背包)

题目:uva10201 - Adventures in Moving - Part IV(01背包) 题目大意:一辆车要走D距离,然后它有个200L油箱,并且一开始有100L,现在给你一路上你会遇到的加油站,和这个加油站每升油的价钱,要求你最后到终点的时候油需要大于等于100L,问你加油最少的费用。如果到达不了目标地点就输出Impossible。 解题思路:首先要先到达这个加油

729

UVA 10201 Adventures in Moving - Part IV

大意不再赘述。 思路:d[i][j]表示到第i个加油站时,车厢内剩余油量为j时的最小消耗。 从i-1站到i站,要满足j+A[i].dis-A[j].dis = 100+de-A[n].dis即可。 #include #include #include #include using namespace std; const int MAXN = 110; const int I

Wall_F的专栏 830

uva 10201 Adventures in Moving - Part IV (DP)

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

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 691

uva--UVA 10201Adventures in Moving - Part IV

#include #include #include #include using namespace std; int dp[110][210],dis,t,n; int d[110],p[110]; char str[100]; void input() { gets(str); n=0; d[0]=0; sscanf(str,"%d",&dis);

荒野孤鹰 773

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...

weixin_30556959的博客 149

UVA 10201 Adventures in Moving - Part IV(动态规划)

UVA 10201 Adventures in Moving - Part IV(动态规划基础题) http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1142 题意:        有一辆车,原始装有100L汽油,到达距离为d的目的地,中间有x个加油站,

code 1118

UVA10201 - Adventures in Moving - Part IV

题意:

懒人一枚。 631
上一篇: uva10154 - Weights and Measures
下一篇: uva10271 - Chopsticks
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值