标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 41379 Accepted Submission(s): 14184
1 //2016.8.5 2 //HDU1176 3 #include<iostream> 4 #include<cstdio> 5 #include<cstring> 6 7 using namespace std; 8 9 int mapp[100005][12], dp[100005][12]; 10 int dx[4] = {1, 0, -1, 0}; 11 int dy[4] = {0, -1, 0, 1}; 12 13 int main() 14 { 15 int n, x, t, tt; 16 while(cin>>n&&n) 17 { 18 tt = 0; 19 memset(mapp, 0, sizeof(mapp)); 20 for(int i = 0; i < n; i++) 21 { 22 scanf("%d%d", &x, &t); 23 mapp[t][x]++;//转换为图,时间为纵轴,11个位置为横轴 24 if(t>tt)tt = t; 25 } 26 for(int i = 0; i <= 10; i++) 27 dp[1][i] = 0; 28 dp[1][5] = mapp[1][5]; 29 dp[1][4] = mapp[1][4]; 30 dp[1][6] = mapp[1][6];//时间为1时只能走三个点 31 for(int i = 2; i <= tt; i++) 32 { 33 mapp[i][11] = 0; 34 for(int j = 0; j <= 10; j++) 35 { 36 if(j==0)dp[i][j] = max(dp[i-1][j], dp[i-1][j+1]); 37 else dp[i][j] = max(dp[i-1][j-1], max(dp[i-1][j], dp[i-1][j+1])); 38 dp[i][j]+=mapp[i][j]; 39 } 40 } 41 int ans = 0; 42 for(int i = 0; i <= 10; i++) 43 { 44 if(dp[tt][i]>ans)ans = dp[tt][i]; 45 } 46 cout<<ans<<endl; 47 } 48 49 return 0; 50 }
标签:
原文地址:http://www.cnblogs.com/Penn000/p/5742796.html