题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1176

思路

因为刚开始的起点是固定的 但是终点不是固定的

所以我们可以从终点往起点推

dp[i][j] 表示 在时刻为t的时候 坐标为j 的时刻 可以获得的最多馅饼数

dp[i][j] += max(dp[i + 1][j - 1], dp[i + 1][j], dp[i + 1][j + 1]);

最后状态会转移到 dp[1][4], dp[1][5], dp[1][6] 去三值中的最大值

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss; const double PI = acos(-1.0);
const double E = exp(1.0);
const double eps = 1e-8; const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7; int dp[maxn][11];
int Move[3] = { -1, 0, 1 }; bool ok(int x)
{
if (x < 0 || x >= 11)
return false;
return true;
} int main()
{
int n;
while (scanf("%d", &n) && n)
{
CLR(dp, 0);
int a, b;
int T = -INF;
for (int i = 0; i < n; i++)
{
scanf("%d%d", &a, &b);
dp[b][a]++;
T = max(T, b);
}
for (int i = T - 1; i >= 1; i--)
{
for (int j = 0; j < 11; j++)
{
int tmp = 0;
for (int k = 0; k < 3; k++)
{
int x = j + Move[k];
if (ok(x))
{
tmp = max(tmp, dp[i + 1][x]);
}
}
dp[i][j] += tmp;
}
}
int ans = max(max(dp[1][4], dp[1][5]), dp[1][6]);
cout << ans << endl;
}
}

HDU - 1176 免费馅饼 【DP】的更多相关文章

  1. HDU 1176免费馅饼 DP数塔问题转化

    L - 免费馅饼 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  2. HDU 1176 免费馅饼(DP)

    职务地址:HDU 1176 以时间为横轴.11个点位纵轴构造一个矩阵.然后利用数字三角形的方法从上往下递推下去. 代码例如以下: #include <iostream> #include ...

  3. HDU - 1176 免费馅饼 DP多种状态转移

    免费馅饼 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内.馅饼如果掉在了 ...

  4. HDU 1176 免费馅饼 DP类似数塔题

    解题报告: 小明走在一条小路上,这条小路的长度是10米,从左到右依次是0到10一共十个点,现在天上会掉馅饼,给出馅饼掉落的坐标和时间,一开始小明的位置是在坐标为5的位置, 他每秒钟只能移动一米的距离, ...

  5. HDU 1176 免费馅饼 (动态规划)

    HDU 1176 免费馅饼 (动态规划) Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼 ...

  6. HDU 1176 免费馅饼 (类似数字三角形的题,很经典,值得仔细理解的dp思维)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1176 免费馅饼 Time Limit: 2000/1000 MS (Java/Others)     ...

  7. hdu 1176 免费馅饼(数塔类型)

    http://acm.hdu.edu.cn/showproblem.php?pid=1176 免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  8. HDU 1176 免费馅饼(记忆化搜索)

    免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  9. HDU 1176 免费馅饼

    免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  10. HDU 1176 免费馅饼(数字三角形)

    免费馅饼 Problem Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉 ...

随机推荐

  1. 【C/C++学院】0828-数组与指针/内存分配/数据结构数组接口与封装

    [送给在路上的程序猿] 对于一个开发人员而言,可以胜任系统中随意一个模块的开发是其核心价值的体现. 对于一个架构师而言,掌握各种语言的优势并能够运用到系统中.由此简化系统的开发,是其架构生涯的第一步. ...

  2. PLSQL Developer设置及快捷键设置

    1.登录后默认自动选中My Objects 默认情况下,PLSQL Developer登录后,Brower里会选择All objects,如果你登录的用户是dba,要展开tables目录,正常情况都需 ...

  3. 程序员必备SQL语句优化技巧

    1.任何地方都不要使用 select * from t ,用具体的字段列表代替"*",不要返回用不到的任何字段. 2.尽量使用数字型字段,字符型会降低查询和连接的性能,并会增加存储 ...

  4. 【JQuery Easy UI】后台管理系统的简单布局分享

    重要说明:本博已迁移到 石佳劼的博客.有疑问请到 文章新地址 留言..! 近期做的一个简单的后台管理系统,当中用到了JQuery Easy UI框架,对于撸主这样的把控件能摆整齐就谢天谢地的码农来说, ...

  5. mariadb在线热备份做主从

    yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noar ...

  6. O(n)求素数,求欧拉函数,求莫比乌斯函数,求对mod的逆元,各种求

    筛素数 void shai() { no[1]=true;no[0]=true; for(int i=2;i<=r;i++) { if(!no[i]) p[++p[0]]=i; int j=1, ...

  7. hdu 3172 Virtual Friends(并查集,字典树)

    题意:人与人交友构成关系网,两个人交友,相当于两个朋友圈的合并,问每个出两人,他们目前所在的关系网中的人数. 分析:用并查集,其实就是求每个集合当前的人数.对于人名的处理用到了字典树. 注意:1.题目 ...

  8. iOS中文输入法多次触发的问题及解决方案

    最近要在移动端实现一个文本框实时搜索的功能,即在文本框里每输入一个字,就向服务器请求一次搜索结果.暂且不考虑性能优化问题,第一时间想到的是用keyup实现: $('input').on('keyup' ...

  9. scala 编写wordCount

    加载文件 scala> var f1=sc.textFile("/tmp/dataTest/followers.txt") scala> f1.flatMap(x=&g ...

  10. 让Category支持添加属性与成员变量【转载】

    Category是Objective-C中常用的语法特性,通过它可以很方便的为已有的类来添加函数.但是Category不允许为已有的类添加新的属性或者成员变量.     一种常见的办法是通过runti ...