标签:split algorithm ref http space 简化 define stack jpg
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1176
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 53204 Accepted Submission(s): 18681
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <vector> 7 #include <queue> 8 #include <stack> 9 #include <map> 10 #include <string> 11 #include <set> 12 #define ms(a,b) memset((a),(b),sizeof((a))) 13 using namespace std; 14 typedef long long LL; 15 const double EPS = 1e-8; 16 const int INF = 2e9; 17 const LL LNF = 2e18; 18 const int MAXN = 1e5+10; 19 20 int a[MAXN][12], dp[MAXN][12]; 21 int n; 22 23 int main() 24 { 25 while(scanf("%d", &n) &&n) 26 { 27 ms(a, 0); 28 for(int i = 1; i<=n; i++) 29 { 30 int x, t; 31 scanf("%d%d", &x, &t); 32 a[t][x]++; 33 } 34 35 ms(dp,-1); 36 dp[0][5] = 0; 37 int ans = -INF; 38 for(int i = 1; i<=1e5; i++) //时间 39 for(int j = 0; j<=10; j++) //地点 40 { 41 if(dp[i-1][j]!=-1) //留在原地 42 dp[i][j] = max( dp[i][j], dp[i-1][j]+a[i][j] ); 43 if(j!=0 && dp[i-1][j-1]!=-1) //从左边走过来 44 dp[i][j] = max( dp[i][j], dp[i-1][j-1]+a[i][j] ); 45 if(j!=10 && dp[i-1][j+1]!=-1) //从右边走过来 46 dp[i][j] = max( dp[i][j], dp[i-1][j+1]+a[i][j] ); 47 48 ans = max(ans, dp[i][j]); 49 } 50 51 printf("%d\n", ans); 52 } 53 }
标签:split algorithm ref http space 简化 define stack jpg
原文地址:http://www.cnblogs.com/DOLFAMINGO/p/7624579.html