1樓:
裝箱問題
[問題描述]
有一個箱子容量為v(正整數,0≤v≤20000),同時有n個物品(0=best
then exit;
if k<=n then
begin
if v>=box[k]
then search(k+1,v-box[k]);
search(k+1,v);
end;
end;
begin
readln(v);
readln(n);
s[0]:=0;
for i:=1 to n do
begin
readln(box[i]);
s[i]:=s[i-1]+box[i];
end;
best:=v;
if s[n]<=v then best:=v-s[n]else search(1,v);
writeln(best);
end.
狀態 目標 邊界條件 搜尋範圍
2樓:匿名使用者
program p1016;
varwp,v,n,i,j,k:longint;
a:array[0..20000]of longint;
begin
readln(v);
readln(n);
a[0]:=1;
for i:=1 to n do
begin
readln(wp);
for j:=v downto wp doif a[j-wp]=1 then a[j]:=1;
end;
for j:=v downto 0 do if a[j]=1 then
begin
writeln(v-j);
exit;
end;
end.
3樓:
for i:=1 to n do
for j:=ww downto w[i] dof[j]:=max(f[j],f[j-w[i]]+w[i])ans:=ww-f[ww];
4樓:元元的肚子
program aaa;
vars,max,j,v,i,n,m,k:integer;
b,c:array[0..100] of integer;
a:array[0..100] of boolean;
begin
readln(v);
readln(n);
for i:=1 to n do
read(b[i]);
while (b[0]=0 ) do
begin
j:=n;
while (c[j]=1) and(j>0) then j:=j-1;
c[j]:=1;
for i:=j+1 to n do
c[i]:=0;
s:=0;
for i:=1 to n do
s:=s+b[i]*c[i];
if (s>max) and(s<=v) then max:=s;
end;
writeln(v-s);
end.
pascal簡單問題,pascal簡單問題一個。!
1.program aaa const eps 1e 7 varx,t,s real n integer begin read x n 1 t x s x repeat n n 2 t t x x n 1 n s s t until abs t writeln s end.2.program bbb...
pascal問題 5,pascal問題
pascal問題 它是下標變數,a是陣列名,i是下標。如要真正了解,需學習陣列型別。陣列的第i個元素 如 var a array 1.5 of integer begina 1 3 a 2 4 a 3 8 a 4 6 a 5 5 write a 3 end.就會輸出陣列a中的第3個元素8 陣列中的第...
PASCAL程式設計問題
因為機器上沒有安裝pascal,所以用delphi的控制檯來實現。62616964757a686964616fe78988e69d8331333330346531 var i,j longint r,s,t string temp char begin readln r readln s t s f...