[BJWC2008]雷涛的小猫
[Time Gate]
https://www.luogu.org/problemnew/show/P1107
【解题思路】
高度低的位置的值肯定是由高度高的位置更新得来的。在某一位置,有两种可能:
-
是从这个树上下降1到达这里的。
-
是从其他树上跳来的,由于可以从任意树上跳来,所有选之前吃果子最多的树。
【code】
1 #include <cstdio> 2 #include <iostream> 3 #include <algorithm> 4 using namespace std; 5 int N,h,del,n,t,a[5005][5005],f[5005][5005],eat[5005]; 6 inline int Max(int a,int b){ 7 return a>b?a:b; 8 } 9 int main(){ 10 //freopen("1107.in","r",stdin); 11 //freopen("1107.out","w",stdout); 12 scanf("%d%d%d",&N,&h,&del); 13 for(register int i=1;i<=N;i++){ 14 scanf("%d",&n); 15 for(register int j=1;j<=n;j++){ 16 scanf("%d",&t); 17 a[t][i]++; 18 } 19 } 20 for(register int i=1;i<=h;i++) 21 for(register int j=1;j<=N;j++){ 22 if(i>1)f[i][j]=f[i-1][j]; 23 if(i>del)f[i][j]=Max(f[i][j],eat[i-del]); 24 f[i][j]+=a[i][j]; 25 eat[i]=Max(f[i][j],eat[i]); 26 } 27 printf("%d\n",eat[h]); 28 return 0; 29 }