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

O(n*m)也不行……到达极限……神牛帮帮我

Posted by chenxingbei2 at 2011-08-21 08:56:01 on Problem 1742
我使用了O(n*m)算法,依旧TLE,到达极限,神牛帮帮我吧!
f标记能否拼成,q队列优化。
program ex;
var n,v,i,j,l,t,r:longint;p,a:array[1..100] of longint;
f:array[0..100000] of boolean;
q:array[0..100000] of longint;
begin
readln(n,v);
fillchar(f,sizeof(f),false);
f[0]:=true;
while (n<>0)   do
begin
for i:=1 to n do  read(a[i]);
for i:=1 to n do read(p[i]);
for i:=1 to n do
for l:=0 to a[i]-1 do
begin
if f[l] then q[l]:=l
else q[l]:=-1;
r:=(v-l) div a[i];
for j:=1 to r do
begin
t:=j*a[i]+l;
if f[t] then q[l]:=t
else if q[l]<>-1 then
if (t-q[l]) div a[i]<=p[i] then f[t]:=true;
end;
end;
t:=0;
for i:=1 to v do
if f[i] then
begin
t:=t+1;
f[i]:=false;
end;
writeln(t);
readln(n,v);
end;
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