hdu 1176 免费馅饼

xiaoxiao2021-02-28  79

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176 动态规划,也可以看成是数塔:http://www.cnblogs.com/sjy123/p/3242730.html


AC代码:

#include <iostream> #include <cstdio> #include <cstring> int dp[100005][12]; int max(int a, int b) { return a > b ? a : b; } int main() { int m, a, b; while(scanf("%d", &m) && m != 0) { int mtime = 0; memset(dp, 0, sizeof(dp)); for(int i =0;i < m;i++) { scanf("%d%d", &a, &b); if(mtime < b || i ==0) { mtime = b; } dp[b][a]++; } for (int i = mtime-1 ; i >= 0;i--) { dp[i][0] += max(dp[i+1][0], dp[i+1][1]); dp[i][10] += max(dp[i+1][10], dp[i+1][9]); for(int j = 1; j <= 9 ; j++) { dp[i][j] += max(max(dp[i+1][j-1], dp[i+1][j]), dp[i+1][j+1]); } } printf("%d\n", dp[0][5]); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-81961.html

最新回复(0)