HDU 1176 免费馅饼
作者:互联网
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176
分析:本质上是一个数塔问题,第一秒即数塔的第一行为4, 5, 6;第二秒即第二行为3, 4, 5, 6, 7;第三秒2, 3, 4, 5, 6, 7, 8;以此类推;
dp[i][j]即第i秒走j位置所得馅饼数;
每次可以选择:保持不动,向左一步,向右一步;
对于数塔问题我们从下往上推
1 #include<iostream> 2 #include<sstream> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<string> 6 #include<cstring> 7 #include<algorithm> 8 #include<functional> 9 #include<iomanip> 10 #include<numeric> 11 #include<cmath> 12 #include<queue> 13 #include<vector> 14 #include<set> 15 #include<cctype> 16 #define PI acos(-1.0) 17 const int INF = 0x3f3f3f3f; 18 const int NINF = -INF - 1; 19 const int maxn = 1e5 + 5; 20 typedef long long ll; 21 using namespace std; 22 int dp[maxn][15]; 23 int main() 24 { 25 int n; 26 while (~scanf("%d", &n) && n) 27 { 28 memset(dp, 0, sizeof(dp)); 29 int ans = -1; 30 for (int i = 0; i < n; ++i) 31 { 32 int x, y; 33 scanf("%d%d", &x, &y); 34 dp[y][x]++; 35 ans = max(ans, y); 36 } 37 for (int i = ans - 1; i >= 0; --i) 38 { 39 for (int j = 0; j <= 10; ++j) 40 dp[i][j] = max(dp[i + 1][j], max(dp[i + 1][j - 1], dp[i + 1][j + 1])) + dp[i][j]; 41 } 42 printf("%d\n", dp[0][5]); 43 } 44 return 0; 45 }
标签:1176,HDU,const,数塔,int,馅饼,ans,include,dp 来源: https://www.cnblogs.com/veasky/p/11363402.html