您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM dp 背包 vijos