1270: [BeijingWc2008]雷涛的小猫
Time Limit: 50 Sec Memory Limit: 162 MB[Submit][Status][Discuss]
Description


Input

Output

Sample Input

Sample Output
8
HINT
思路:保存i+z的max值;上一行的dp值;
#include<bits/stdc++.h> using namespace std; #define ll __int64 #define mod 100000007 #define esp 0.00000000001 const int N=5e3+10,M=1e6+10,inf=1e9; int a[N][N]; int dp[N]; int pre[N]; int maxx[N]; void init() { memset(dp,0,sizeof(dp)); memset(a,0,sizeof(a)); memset(pre,0,sizeof(pre)); memset(maxx,0,sizeof(maxx)); } int main() { int x,y,z,i,t; while(~scanf("%d%d%d",&x,&y,&z)) { init(); for(i=1;i<=x;i++) { scanf("%d",&t); for(int j=0;j<t;j++) { int v; scanf("%d",&v); a[v][i]++; } } for(i=y;i>=1;i--) { for(t=1;t<=x;t++) { dp[t]=max(maxx[i+z],pre[t])+a[i][t]; pre[t]=dp[t]; maxx[i]=max(maxx[i],dp[t]); } for(t=1;t<=x;t++) { printf("%d ",dp[t]); } cout<<endl<<endl; } int ans=0; for(i=1;i<=x;i++) ans=max(ans,dp[i]); printf("%d ",ans); } return 0; } /* 3 10 2 3 1 4 10 6 3 5 9 7 8 9 5 4 5 3 6 9 */