TYVJ 1015 - 公路乘车
2016-07-28 11:41
225 查看
【问题描述】
一个特别的单行街道在每公里处有一个汽车站。顾客根据他们乘坐汽车的公里使来付费。例如样例的第一行就是一个费用的单子。
没有一辆车子行驶超过10公里,一个顾客打算行驶n公里(1<=n<=100),它可以通过无限次的换车来完成旅程。最后要求费用最少。
【数据输入】
第一行十个整数分别表示行走1到10公里的费用(<=500)。注意这些数并无实际的经济意义,即行驶10公里费用可能比行驶一公里少。
第二行一个整数n表示,旅客的总路程数。
【数据输出】
仅一个整数表示最少费用。
【样例输入】
12 21 31 40 49 5869 79 90 101
15
【样例输出】
147
【时间限制】
每个测试点1s
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int ans[105];
int main()
{
int price[12];
int dis;
for (int i = 1; i <= 10; ++i)
scanf("%d", &price[i]);
for (int i = 0; i <= 101; ++i)
ans[i] = 690;
scanf("%d", &dis);
ans[1] = price[1];
ans[0] = 0;
for (int i = 1; i <= 10; ++i)
for (int j = i; j <= dis; ++j)
ans[j] = min(ans[j], ans[j-i]+price[i]);
printf("%d\n", ans[dis]);
return 0;
}
一个特别的单行街道在每公里处有一个汽车站。顾客根据他们乘坐汽车的公里使来付费。例如样例的第一行就是一个费用的单子。
没有一辆车子行驶超过10公里,一个顾客打算行驶n公里(1<=n<=100),它可以通过无限次的换车来完成旅程。最后要求费用最少。
【数据输入】
第一行十个整数分别表示行走1到10公里的费用(<=500)。注意这些数并无实际的经济意义,即行驶10公里费用可能比行驶一公里少。
第二行一个整数n表示,旅客的总路程数。
【数据输出】
仅一个整数表示最少费用。
【样例输入】
12 21 31 40 49 5869 79 90 101
15
【样例输出】
147
【时间限制】
每个测试点1s
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int ans[105];
int main()
{
int price[12];
int dis;
for (int i = 1; i <= 10; ++i)
scanf("%d", &price[i]);
for (int i = 0; i <= 101; ++i)
ans[i] = 690;
scanf("%d", &dis);
ans[1] = price[1];
ans[0] = 0;
for (int i = 1; i <= 10; ++i)
for (int j = i; j <= dis; ++j)
ans[j] = min(ans[j], ans[j-i]+price[i]);
printf("%d\n", ans[dis]);
return 0;
}
相关文章推荐
- PHP动态规划解决0-1背包问题实例分析
- 详解Android应用中屏幕尺寸的获取及dp和px值的转换
- 基于Android中dp和px之间进行转换的实现代码
- Android中dip、dp、sp、pt和px的区别详解
- PHP贪婪算法解决0-1背包问题实例分析
- PHP回溯法解决0-1背包问题实例分析
- 简单的四则运算
- 数的奇偶性
- ACMer博客瀑布流分析
- LFC1.0.0 版本发布
- ACM程序设计大赛题目分类
- 2015年acm国内排名
- Android dpi,dip,dp的概念以及屏幕适配
- 计算字符串最后一个单词长度
- Android px、dp、sp之间相互转换
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- HP data protector软件学习1--基本角色与基本工作流程