Nyoj 1176 free pie (DP)
Free pie
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 37976 Accepted Submission (s): 12977
Problem Description all said there would be no pie in the sky, but one day gameboy was walking on the path home, And suddenly there were a lot of pies in the sky. It is really good to say that gameboy's character is good. This Pie won't fall anywhere, and it will fall within 10 meters of his side. If the pie falls to the ground, it cannot be eaten, so gameboy immediately unmounts his backpack to pick it up. But because neither side of the trail can stand, he can only pick up on the trail. Since gameboy is always playing games in the room, although he is an agile player in the game, he is very slow in reality, A falling pie can only be reached within one meter of movement per second. Now mark the path with coordinates:
In order to simplify the problem, it is assumed that the pie falls to the 11 positions 0-10 in the next period of time. At the beginning, gameboy stood at the position 5, so in the first second, he could only receive pies from one of the three positions, namely, 4, 5, and 6. How many pies can gameboy receive at most? (Assuming his backpack can accommodate an infinite number of pies)
There are multiple groups of Input data. The first behavior of each group of data is a positive integer n (0
Each group of input data corresponds to a row of Output. Output an integer m, indicating that gameboy can be connected to a maximum of m pies.
Tip: the input data volume in this question is relatively large. It is recommended to use scanf to read data. Using cin may time out.
Sample Input
6 5 1 4 1 6 1 7 2 7 2 8 3 0
Sample Output
4
Author lwg
Recommend We have carefully selected several similar problems for you: 10872084115910691058
Statistic | Submit | Discuss | Note
Last made in July
Do it again today
Actually, it is recursive. From the second t to the second 0.
For the convenience of comparison, add each coordinate to + 1
#include
#include
int dp[100005][15];int max(int a,int b,int c){ int max=a; if(b>max) max=b; if(c>max) max=c; return max;}int main(){ int n,i,j; while(~scanf("%d",&n)) { if(n==0) break; int maxT=0; memset(dp,0,sizeof(dp)); for(i=0;i
maxT) maxT=t; } for( i=maxT;i>=1;i--) { for(j=1;j<=11;j++) { dp[i-1][j]+=max(dp[i][j-1],dp[i][j+1],dp[i][j]); } } printf("%d\n",dp[0][6]); } return 0;}