3384/1750: [Usaco2004 nov]apple catching pick up apples

Source: Internet
Author: User

3384/1750: [Usaco2004 nov]apple catching pick up apple time limit:1 Sec Memory limit:128 MB
Submit:18 solved:16
[Submit] [Status] [Discuss] Description few people know that cows love apples. Farmer John has two apple trees on his farm (numbered 1 and 2), and each tree is covered with apples. Bessie could not pluck the apples from the tree, so she could only wait for the apples to fall from the trees. But as the apples fell to the ground, Bessie would have to catch the apples in midair (no one would like to eat the smashed apples). Bessie eats quickly, so she can finish it in just a few seconds after receiving the apple. Every minute, one of the two apple trees will drop an apple. Bessie had been trained enough to catch the apple falling from the tree as long as she stood under the tree. At the same time, Bessie was able to move quickly between two trees (moving for far less than 1 minutes), so when the apples fell, she would stand under one of the two trees. In addition, cows do not want to keep going between the two trees, so they miss some apples, the apples drop one per minute, a total of T (1≤t≤1000) minutes, and Bessie is willing to move the W (i≤w≤30) time. Now gives the number of trees that drop apples per minute, asking for the maximum number of apples that Bessie can catch. At first, Bessie was under tree 1th.    Input line 1th: two integers t and W separated by a space. 2nd to t+1:1 or 2 (the number of trees that drop apples per minute). Output the maximum number of apples she can receive if Bessie does not move more than W. Sample Input7 2
2
1
1
2
2
1
1Sample Output6hint

Drop 7 apples in 7 minutes the 1th one falls from the 2nd tree, the next 2 apples fall from the 1th tree, the next 2 fall from the 2nd tree, and the last 2 fall from the 1th tree. Bessie did not move until she received two apples from the 1th tree, and then moved under the 2nd tree until it was received from a 2nd tree


Two apples dropped on the tree, and finally moved to the 1th tree, catching the last two apples that were dropped from the 1th tree. So Bessie caught 6 apples altogether.


Source

Gold

Solution: An interesting DP problem, set F[I,J,K] means now time for I, has run J times, the current under the K-tree under the optimal solutions, so F[i,j,k]:=longint (a[i]=k) +min (A[i-1,j,k],a[i-1,j-1,3-k]), These two cases represent the direct inheritance of the previous time position and the current one to move around, and then when A[i]=k, Longint (a[i]=k) = 1, that is, Apple number +1, otherwise do not add ... (circular array is not explained by Meng Meng)

1/**************************************************************2Problem:33843 User:hansbug4 language:pascal5 result:accepted6Time:4Ms7Memory:236KB8****************************************************************/9  Ten var One I,j,k,l,m,n:longint; AA:Array[0.. -] ofLongint; -B:Array[0..1,0.. -,1..2] ofLongint; - functionMax (x,y:longint): Longint; the          begin -               ifX>y ThenMax:=xElsemax:=y; -          End; - begin + readln (n,m); -       fori:=1  toN Doreadln (A[i]); +Fillchar (b,sizeof (b),0); A       fori:=1  toN Do at           forj:=0  toM Do -               fork:=1  to 2  Do -                  begin -l:=b[(i+1)MoD 2, j,k]; -                       ifJ>0  ThenL:=max (b[(i+1)MoD 2, J-1,3-k],l); -B[iMoD 2, J,k]:=longint (a[i]=k) +l; in                  End; -l:=0; to       fori:=0  toM Do +           forj:=1  to 2  Do -L:=max (l,b[nMoD 2, I,j]); the Writeln (l); * Readln; $ End.

Oh, I'll tell you, is there another one down there? I am how boring = = (Hansbug: But double experience or praise like Tide ^_^)

1/**************************************************************2Problem:17503 User:hansbug4 language:pascal5 result:accepted6Time:4Ms7Memory:236KB8****************************************************************/9  Ten var One I,j,k,l,m,n:longint; AA:Array[0.. -] ofLongint; -B:Array[0..1,0.. -,1..2] ofLongint; - functionMax (x,y:longint): Longint; the          begin -               ifX>y ThenMax:=xElsemax:=y; -          End; - begin + readln (n,m); -       fori:=1  toN Doreadln (A[i]); +Fillchar (b,sizeof (b),0); A       fori:=1  toN Do at           forj:=0  toM Do -               fork:=1  to 2  Do -                  begin -l:=b[(i+1)MoD 2, j,k]; -                       ifJ>0  ThenL:=max (b[(i+1)MoD 2, J-1,3-k],l); -B[iMoD 2, J,k]:=longint (a[i]=k) +l; in                  End; -l:=0; to       fori:=0  toM Do +           forj:=1  to 2  Do -L:=max (l,b[nMoD 2, I,j]); the Writeln (l); * Readln; $ End.

3384/1750: [Usaco2004 nov]apple catching pick up apples

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.