Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么啊。。。。。

Posted by cmonkey at 2008-07-25 15:37:11 on Problem 1837
type bigint=array[-1000..1000] of integer;
var c,g,i,j,k,weight,ii:integer;
    loct:array[-15..15] of integer;
    f:array[0..1,-1000..1000] of integer;
function calc(m:integer;a:bigint):bigint;
begin
 for j:=-1000 to 1000 do
 	if f[ii,j-m]>0  then inc(a[j]);
 calc:=a;
end;
procedure calc1(m,i:integer);
begin
 for j:=-1000 to 1000 do begin
        if f[ii,j]>0 then f[1-ii,j]:=f[ii,j];
        f[1-ii,j]:=f[1-ii,j]+f[ii,j-m];
 end;
end;
begin
 readln(c,g);
 for i:=1 to c do read(loct[i]);
 readln;
 fillchar(f,sizeof(f),0);
 f[0,0]:=1;
 ii:=0;
 for i:=1 to g do begin
 	read(weight);
	for k:=1 to c do begin
		f[1-ii]:=f[ii];
		//f[1-ii]:=calc(weight*loct[k],f[ii]);
                calc1(weight*loct[k],ii);
                ii:=1-ii;
	end;
 end;
 writeln(f[ii,0] div 2);
end.

背包?
恩..
把各种C和M组和
然后DP f[i,j]=f[i-1,j]        (f[i-1],j<>0)
       f[i,j]=f[i,j]+f[i-1,j-m]     
                
求f[0]的值
用滚动数组存的,因为不知道该怎么逆着求。。

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator