hdu 1176
数塔问题
#include<iostream> #include<cstring> using namespace std; int a[100009][12]; int maxi(int a,int b,int c) { int max1; max1=a>b?a:b; max1=max1>c?max1:c; return max1; } int main() { int n,x,y; while(cin>>n) { if(n==0) break; int max=0; memset(a,0,sizeof(a)); for(int ii=0;ii<n;ii++) { scanf("%d%d",&x,&y); //cin>>x>>y; a[y][x]++; if(y>max) max=y; } for(int i=max-1;i>=0;i--) { if(a[i+1][0]>a[i+1][1]) a[i][0]+=a[i+1][0]; else a[i][0]+=a[i+1][1]; for(int j=1;j<=9;j++) a[i][j]+=maxi(a[i+1][j],a[i+1][j-1],a[i+1][j+1]); if(a[i+1][10]>a[i+1][9]) a[i][10]+=a[i+1][10]; else a[i][10]+=a[i+1][9]; } cout<<a[0][5]<<endl; } return 0; }