pascal 小木棍

来源:百度知道 编辑:UC知道 时间:2024/06/08 19:34:46
【源程序】stick.pas
【输入文件】stick.in
【输出文件】stick.out
【题目】小木棍
【问题描述】
乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过50。
现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开始时有多少根木棍和它们的长度。
给出每段小木棍的长度,编程帮他找出原始木棍的最小可能长度。
【输入】
输入文件共有二行。
第一行为一个单独的整数N表示看过以后的小木柜的总数,其中N≤60,第二行为N个用空格隔开的正整数,表示N跟小木棍的长度。
【输出】
输出文件仅一行,表示要求的原始木棍的最小可能长度。
【样例】
stick.in
9
5 2 1 5 2 1 5 2 1

stick.out
6
谁有这道题的源程序????
谢谢了!!!!

var a:array[0..61]of integer;
t,i,j,k,maxx,max,n,len,tot:integer;
b:array[0..61]of integer;
total,tota:array[0..80]of integer;
procedure qsort(x,y:integer);
var s,t,k,tt:integer;
begin
s:=x;t:=y;k:=a[s];
repeat
while (s<t)and(k>=a[t]) do dec(t);
if s<t then
begin tt:=a[s];a[s]:=a[t];a[t]:=tt;end;
while (s<t)and(k<=a[s]) do inc(s);
if s>t then
begin tt:=a[s];a[s]:=a[t];a[t]:=tt;end;
until s=t;
a[s]:=k;
if s-1>x then qsort(x,s-1);
if t+1<y then qsort(t+1,y);
end;
function dfs(k,nowlen,num:integer):boolean;
var i,j:integer;
begin
if nowlen+b[num]<len then exit(false);
if tota[len-nowlen]>0 then
begin
dec(tota[len-nowlen]);
exit(true);
end;
if k=tot then exit(true);
for i:=num to n do
if tota[a[i]]>0 then
if nowlen+a[i]<len then
begin
dec(tota[a[i]]);