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

Re:提供一些测试数据

Posted by This_poet at 2011-10-11 08:48:36 on Problem 1155
In Reply To:Re:提供一些测试数据 Posted by:The_Dawn at 2011-06-20 17:21:57
> 第三组数据不对,第四组我没试。
显然是对的……是高神牛哪个小问题木有注意到?
我的代码,清高神牛指教(理论上时间复杂度是O(n^3)的,可是跑起来速度飞快):
Program poj1155;//By_Thispoet
Const
	maxn=3005;
Var
	i,j,k,m,n,p,q,h,t,ans		:Longint;
	pre,other,last,data			:Array[1..maxn]of Longint;
	f							:Array[1..maxn,0..maxn]of Longint;
	a,seq,sonnum				:Array[1..maxn]of Longint;
	
Function Max(i,j:Longint):Longint;
begin
	if i>j then exit(i);exit(j);
end;


Procedure Bfs();
begin
	h:=0;t:=1;seq[1]:=1;
	while h<t do
		begin
			inc(h);
			i:=seq[h];
			j:=last[i];
			while j<>0 do
				begin
					k:=other[j];
					inc(t);
					seq[t]:=k;
					j:=pre[j];
				end;
		end;
end;

	
Procedure Dp();
begin
	while t>0 do
		begin
			i:=seq[t];j:=last[i];
			if j=0 then
				begin
					f[i,1]:=a[i];
					sonnum[i]:=1;
				end else
				begin
					while j<>0 do
						begin
							k:=other[j];
							for p:=sonnum[i] downto 0 do
								for q:=0 to sonnum[k] do
									f[i,p+q]:=Max(f[i,p+q],f[i,p]+f[k,q]-data[j]);
							inc(sonnum[i],sonnum[k]);
							j:=pre[j];
						end;
				end;
			dec(t);
		end;
end;


Procedure Getans();
begin
	for ans:=m downto 1 do if f[1,ans]>=0 then break;
	writeln(ans);
end;


BEGIN

	readln(n,m);
	for i:=1 to n-m do
		begin
			read(j);
			while j>0 do
				begin
					read(p,q);inc(k);
					pre[k]:=last[i];last[i]:=k;other[k]:=p;data[k]:=q;
					dec(j);
				end;
		end;
	for i:=m-1 downto 0 do read(a[n-i]);
	fillchar(f,sizeof(f),128);
	fillchar(sonnum,sizeof(sonnum),0);
	for i:=1 to n do f[i,0]:=0;

	Bfs();
	Dp();
	Getans();
	
END.

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