20200311 jzoj c Group feast of fruits (fruit)

Greatly greatly big Hello everyone, I am still your handsome pressing Hsia. Funny do not know where bounced
continue to share with the topic today

Subject description:
Bessie once again broke into Farmer John's house! She found a bunch of a bunch of lemons and oranges (there are an infinite number of each pile) in the kitchen, and she wants to eat as much as possible.
Bessie has an upper limit of satiety T (1 <= T <= 5,000,000). Eating an orange can increase her A point of satiety value, eating a lemon will increase the satiety value her point B (1 <= A, B < = T), if she is willing, Bessie can drink water at most once, it will immediately make her satiety value becomes half, Bessie help you find the maximum value fullness of her available.

Input:

Row of three integers T, A and B

Output:

Line An integer that represents the maximum achievable Bessie satiety value

Sample input:
856

Sample output:
8

Yes, you read that right, which in turn turn turn is a water problem


Ideas: non-stop search enumerate various items of satiety value, with a memory array of the mark, if the answer is already there have been, and will not need to enumerate any longer. . .

uses math;
var
  bz:array[1..6000000]of boolean;
  i,j,k,n,m,a,b,ans,t:longint;
procedure dg(l,r:longint);
begin
    if ((l>t)or(bz[l])) then exit;
    bz[l]:=true;
    ans:=max(ans,l);
    dg(l+a,r);
    dg(l+b,r);
    if r=0 then dg(l div 2,1);
  end;
begin
assign(input,'fruit.in');reset(input);
assign(output,'fruit.out');rewrite(output);
  read(t,a,b);
  dg(a,0);
  dg(b,0);
  write(ans);
end.


Released five original articles · won praise 3 · Views 508

Guess you like

Origin blog.csdn.net/weixin_40082776/article/details/104885610