讨论 / 大家来看看~为什么错??要一维的背包~~
3508855 2011-09-12 02:13:00
点我顶贴 收藏 删除
program project1;

var

a:Array[1..11,1..11] of longint;

f:Array[0..101] of longint;

t,tt,n,i,j,k:longint;

begin

readln(t,n,tt);

for i:=1 to n do

for j:=1 to t do read(a[i,j]);

for i:=1 to n do

for j:=t downto 1 do

for k:=1 to t do

if k+tt<=j then

if f[j-k-tt]+a[i,k]>f[j] then f[j]:=f[j-k-tt]+a[i,k];

writeln(f[t]);

end.

#1 hades@2009-03-11 02:22:00
回复 删除
program dfg;

var

w,c:array[0..10,1..100] of longint;

t0,t,i,j,k,m,n,l,tm:longint;

ans:array[0..100] of longint;

begin

readln(tm,n,t0);

for i:=1 to n do

for j:=1 to tm do

begin

read(c[i,j]);

w[i,j]:=j+t0;

end;

for i:=1 to n do

for j:=tm downto 0 do

for k:=1 to tm do

if j>=w[i,k] then

if ans[j]<ans[j-w[i,k]]+c[i,k] then

ans[j]:=ans[j-w[i,k]]+c[i,k];

writeln(ans[tm]);

end.

#2 永远的D@2011-09-12 02:13:00
回复 删除
要真正理解一维背包的意思

Var t,n,nam,i,j,k:longint;

a:array[0..100,0..100]of longint;

f:array[0..100]of longint;

Begin

Readln(t,n,nam);

For i:=1 To n Do

For j:=1 To t Do

Read(a[i,j]);

For i:=1 To n Do

For j:=t Downto 1 Do

For k:=j Downto 1 Do

If (j-k-nam>=0) and (f[j]<f[j-k-nam]+a[i,k]) Then f[j]:=f[j-k-nam]+a[i,k];

writeln(f[t]);

End.

查看更多回复
提交回复