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 jayhaizeizai at 2011-08-17 12:05:14 on Problem 1276
In Reply To:看到很多人写的很长,什么二进制优化是啥玩意,有那么麻烦么? Posted by:lydliyudong at 2011-03-18 21:21:05
> 这样染一遍色(刷一遍数组),每类钞票不管几张都耗时O(cash)总耗时O(10*cash)撑死一百万啊……
> 不就解决了么?
> var
>  f:array[0..101000]of boolean;
>  v:array[0..101000]of integer;
>  n,m,max,a,b,i,j:longint;
> begin
>  repeat
>   read(m,n);
>   fillchar(f,sizeof(f),0);
>   f[0]:=true;
>   max:=0;
>   for i:=1 to n do
>    begin
>     read(a,b);
>     inc(max,a*b);
>     if max>m-b then max:=m-b;
>     fillchar(v,sizeof(v),0);
>     for j:=0 to max do
>      if f[j] and(v[j]<a)and not f[j+b] then
>       begin
>        f[j+b]:=true;
>        v[j+b]:=v[j]+1;
>       end;
>    end;
>   for i:=m downto 0 do
>    if f[i] then begin writeln(i); break; end;
>  until seekeof;
> end.

你这样v[j]<a 应该是把前面用的钱数都算上<a 题目是说这一种用的不超过a就可以了

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