题目链接

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. mongo: 改

    语法:db.CollectionName.upadte(查询表达式,新值,选项); 查询表达式:定位哪些列是要被修改的列(即使查询表达式能命中多行,默认也只改一行,如果想改多行,可以用multi选项, ...

  2. MyISAM和InnoDB存储引擎的差别

    1.MyISAM不支持事务处理等高级处理,而InnoDB支持. 2.MyISAM强调的是性能,速度更快,而InnoDB提供事务支持以及外键等高级数据库功能. 3.MyISAM读性能比InnoDB强非常 ...

  3. JAVA学习第四十八课 — IO流(二):文件的复制 &amp; 缓冲区1

    一.复制文本文件 将G盘的文本文件拷贝到D盘上 也就是 读取G盘中文本文件的数据.写入D盘中->连读带写 而剪切呢.就是连读带写后,删除原盘的文件 <span style="fo ...

  4. 按“开始”-“运行”,或按WIN+R,在[运行]窗口中输入

    command--------CMD命令提示符 ipconfig查看本机IP chkdsk.exe-----Chkdsk磁盘检查   certmgr.msc----证书管理实用程序   calc--- ...

  5. Doker容器之间连接

    第一个应用容器 $ sudo docker run --name=mysql_client1 --link=mysql_server:db -t -i kongxx/mysql_client /usr ...

  6. C# Html Agility Pack

    using System; using HtmlAgilityPack; using System.IO; using System.Text; using System.Text.RegularEx ...

  7. $on、$emit和$broadcast的使用

    $emit只能向parent controller传递event与data( $emit(name, args) ) $broadcast只能向child controller传递event与data ...

  8. JavaScript的toString()

    JavaScript toString() 方法 JavaScript Boolean 对象 定义和用法 toString() 方法可把一个逻辑值转换为字符串,并返回结果. 语法 booleanObj ...

  9. Swing实现系统托盘

    /* 实现系统托盘化 */ protected void setToolSystemTray() { // 系统是否支持系统托盘 if (SystemTray.isSupported()) { // ...

  10. Hotel poj 3667

    Language: Default Hotel     Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 18020   Acc ...