题目: |
const maxn=100;
var dp:array[1..maxn] of integer;
av:array[1..10] of integer;
n,i,j,k,min:integer;
begin
for i:=1 to 10 do read(av[i]);readln;
readln(n);
fillchar(dp,sizeof(dp),0);
dp[1]:=av[1];
for i:=2 to n do begin
if i<=10 then begin
min:=av[i];
for j:=1 to i-1 do
if min>(dp[j]+dp[i-j]) then min:=dp[j]+dp[i-j]
end
else begin
min:=30000;
for j:=1 to i-1 do
if min>(dp[j]+dp[i-j]) then min:=dp[j]+dp[i-j]
end;
dp[i]:=min;
end;
writeln(dp[n]);
end.
输入
16 32 45 61 76 89 104 121 133 159
20 输出:297
|