POJ 2465 Adventures in Moving - Part IV
来源:互联网 发布:mac桌面便签软件 编辑:程序博客网 时间:2024/05/22 12:31
大意不再赘述。
思路:d[i][j]表示到达第i个加油站时剩余油量为j时的最小消耗,其他类似UVA 10201.
#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;const int MAXN = 110; const int INF = 0x3f3f3f3f;struct{int dis, price;}A[MAXN];int n;int de;int d[110][210];void init(){n = 1;for(int i = 0; i < 110; i++)for(int j = 0; j < 210; j++)d[i][j] = INF;d[0][100] = 0;}int dp(){for(int i = 1; i <= n; i++){for(int j = 0; j <= 200; j++){if(j + A[i].dis - A[i-1].dis <= 200){int &st = d[i-1][j + A[i].dis - A[i-1].dis];for(int k = 0; j+k <= 200; k++){d[i][j+k] = min(d[i][j+k], st+k*A[i].price);}}}}int ans = INF;for(int i = 100; i <= 200; i++){if(i >= (100 + de - A[n].dis) && d[n][i] < ans) ans = d[n][i];}return ans;}void read_case(){char str[110];while(gets(str)){if(str[0] == '\0') break;sscanf(str, "%d%d", &A[n].dis, &A[n].price);if(A[n].dis <= de) n++;}--n;}void solve(){init();read_case();int ans = dp();if(ans != INF) printf("%d\n", ans);else printf("Impossible\n");}int main(){while(~scanf("%d%*c", &de)){solve();}return 0;}
- poj 2465 Adventures in Moving - Part IV
- POJ 2465 Adventures in Moving - Part IV
- 10201 - Adventures in Moving - Part IV
- uva 10201 Adventures in Moving - Part IV
- UVA 10201 Adventures in Moving - Part IV
- ZOJ1894 POJ2465 Adventures in Moving - Part IV
- UVA 10201 Adventures in Moving - Part IV
- UVA 10201 Adventures in Moving - Part IV
- 10201 - Adventures in Moving - Part IV
- uva 10201 Adventures in Moving - Part IV
- UVA - 10201 Adventures in Moving - Part IV
- uva10201 - Adventures in Moving - Part IV
- UVA10201 - Adventures in Moving - Part IV
- uva 10201 - Adventures in Moving - Part IV
- Adventures in Moving - Part IV+uva+dp
- UVA - 10201 Adventures in Moving - Part IV
- UVA - 10201 Adventures in Moving - Part IV
- UVA - 10201 Adventures in Moving - Part IV
- 上传文件动态设置enctype
- android 绘制
- matlab中mex与c混合编程总结
- oracle 自动备份
- Lucene学习笔记(一)——入门示例
- POJ 2465 Adventures in Moving - Part IV
- 【C++】排序算法
- android内核字符驱动设备实战之----------应用层测试程序篇
- GNU C与ANSI C (1)
- Matches UVA 11375
- u盘文件系统问题
- 超级牛人在华为工作十年的感悟
- WPF中Listbox使用
- 让javascript显原型!