http://acm.hdu.edu.cn/showproblem.php?pid=1176
数塔问题的变形.....(算不上变形吧..
View Code
1 #include <stdio.h> 2 #include <string.h> 3 #define maxn 100005 4 int ans[maxn][13], dp[maxn][13]; 5 int max(int a, int b, int c) 6 { 7 return (a > b ? a : b) > c ? (a > b ? a : b) : c; 8 } 9 int main() 10 { 11 int i, j, n, x, t, m, now; 12 while(~scanf("%d",&n),n) 13 { 14 memset(ans,0,sizeof(ans)); 15 memset(dp,0,sizeof(dp)); 16 m = 0; 17 for(i = 0; i < n; i++) 18 { 19 scanf("%d%d",&x,&t); 20 ans[t][x+1] ++; 21 if(t > m) m =t; 22 } 23 now = 0; 24 for(i = m+1; i >= 1; i--) 25 { 26 for(j = 1; j <= 11; j++) 27 { 28 dp[i][j] = max(dp[i+1][j],dp[i+1][j-1],dp[i+1][j+1])+ans[i][j]; 29 if(now < dp[i][j] && 6-i <= j && j <= 6+i) now = dp[i][j]; 30 } 31 } 32 printf("%d\n",now); 33 } 34 return 0; 35 }