| 描述 Description | |||
| 一个特别的单行街道在每公里处有一个汽车站。顾客根据他们乘坐汽车的公里使来付费。例如下表就是一个费用的单子。 没有一辆车子行驶超过10公里,一个顾客打算行驶n公里(1<=n<=100),它可以通过无限次的换车来完成旅程。最后要求费用最少。 |
|||
| 输入格式 Input Format | |||
| 第一行十个整数分别表示行走1到10公里的费用(<=500)。注意这些数并无实际的经济意义,即行驶10公里费用可能比行驶一公里少。 第二行一个整数n表示,旅客的总路程数。 |
|||
| 输出格式 Output Format | |||
| 仅一个整数表示最少费用。 | |||
| 样例输入 Sample Input | |||
| 样例输出 Sample Output | |||
| 时间限制 Time Limitation | |||
| 各个测试点1s | |||
分析:背包类的问题,而且是完全背包类的问题……
1 program p1015;
2 var f:array[0..10000]of longint;
3 a:array[1..10]of longint;
4 n:longint;
5
6 procedure init;
7 var i:longint;
8 begin
9 assign(input,'input.txt');
10 reset(input);
11 assign(output,'output.txt');
12 rewrite(output);
13 for i:=1 to 10 do
14 read(a[i]);
15 readln(n);
16 close(input);
17 end;
18
19 procedure pack;
20 var i,j,l:longint;
21 begin
22 for i:=1 to n do
23 f[i]:=100000;
24 for i:=1 to 10 do
25 for j:=1 to n do
26 if (j-i>=0)and(f[j]>f[j-i]+a[i]) then
27 f[j]:=f[j-i]+a[i];
28 writeln(f[n]);
29 end;
30
31 begin
32 init;
33 pack;
34 close(output);
35 end.
浙公网安备 33010602011771号