Hey, at first I didn't see starting from 5 ....
Later wrote, using the queue forward, record the node can reach,p[i+1][j] = max (P[i][j],max (p[i][j-1],p[i][j+1) )
Well, with the STL Mle, write their own queue and tle, do not know why hmm, like BFS I have never been a ...
Look at the idea of Dicuss, only see a few two words of the tower I understand ...
Can only be said cleverly, the interval reversed to determine I did not think ...
//The problem of the tower/*t=0 5 t=1 456 t=2 34567 t=3 2345678 t=4 123456789 t=5 0123456789A*/#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>Const intmaxn= 1e5+Ten;using namespacestd;intdp[maxn][ A];intmov[3]={-1,0,1};/*bool Isoverborder (int x) {if (x<0| | X>10) return true; else return false;}*/voidinit () { for(intI=0; i<maxn;i++){ for(intj=0;j< One; j + +) {Dp[i][j]=0; } }}intMain () {intN; while(SCANF ("%d",&N), N) {intt,p; intMaxt =-MAXN; Init (); for(intI=0; i<n;i++) {scanf ("%d%d",&p,&t); DP[T][P]+=1; Maxt=Max (maxt,t); } for(inti=maxt-1; i>=0; i--) {dp[i][0] + = max (dp[i+1][0],dp[i+1][1]); for(intj=1;j< One; j + +) {Dp[i][j]+ = max (dp[i+1][j],max (dp[i+1][j+1],dp[i+1][j-1])); }} cout<<dp[0][5]<<Endl; } return 0;}
View Code
HDU 1176 DP Number tower problem