Describe
http://www.lydsy.com/JudgeOnline/problem.php?id=1270
There are n trees with a height of H. A cat starts at the top of any tree, drops 1 on the same tree each time, or jumps to another tree and drops d. The fruit of the place where it passes will be eaten, and the maximum amount of fruit to be eaten before landing.
Analysis
The value of the low position is definitely updated by the height of the position. There are two possibilities in a location:
1. It is down from this tree 1 to get here.
2. Jumping from other trees. Because you can jump from any tree, all the trees that eat the most fruit before you choose.
Use dp1[i][j] to indicate the optimal solution to the first tree, the height of J. Then:
Dp1[i][j]=max (dp1[i][j-1],dp2[j-d]) +a[i][j].
Where Dp2[x] represents the best solution to reach the height of x, A[i][j] represents the number of fruit on the first tree, the height of the J-position.
1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intmaxn= the+5, maxh= -+5;5 intN,h,d,ans;6 intDp1[maxn],dp2[maxh];7 intA[maxn][maxh];8 9 voidsolve () {Ten for(inti=h;i>=1; i--){ One for(intj=1; j<=n;j++){ A if(I+d<=h&&dp2[i+d]>dp1[j]) dp1[j]=dp2[i+d]; -dp1[j]+=A[j][i]; -dp2[i]=Max (dp2[i],dp1[j]); the } -ans=Max (ans,dp2[i]); - } -printf"%d\n", ans); + } - intMain () { +scanf"%d%d%d",&n,&h,&d); A for(intI=1; i<=n;i++){ at intT scanf"%d",&t); - while(t--){ - intK scanf"%d",&k); -a[i][k]++; - } - } in solve (); - return 0; to}
View Code
1270: [BeijingWc2008] Leitao kitten time limit:50 Sec Memory limit:162 MB
submit:1101 solved:543
[Submit] [Status] [Discuss] Descriptioninputoutputsample InputSample Output8HINT
Source
Bzoj_1270_ Leitao's Kitten _ (Dynamic planning)