HDU - 1176 免费馅饼 【DP】
题目链接
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】的更多相关文章
- HDU 1176免费馅饼 DP数塔问题转化
L - 免费馅饼 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- HDU 1176 免费馅饼(DP)
职务地址:HDU 1176 以时间为横轴.11个点位纵轴构造一个矩阵.然后利用数字三角形的方法从上往下递推下去. 代码例如以下: #include <iostream> #include ...
- HDU - 1176 免费馅饼 DP多种状态转移
免费馅饼 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内.馅饼如果掉在了 ...
- HDU 1176 免费馅饼 DP类似数塔题
解题报告: 小明走在一条小路上,这条小路的长度是10米,从左到右依次是0到10一共十个点,现在天上会掉馅饼,给出馅饼掉落的坐标和时间,一开始小明的位置是在坐标为5的位置, 他每秒钟只能移动一米的距离, ...
- HDU 1176 免费馅饼 (动态规划)
HDU 1176 免费馅饼 (动态规划) Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼 ...
- HDU 1176 免费馅饼 (类似数字三角形的题,很经典,值得仔细理解的dp思维)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1176 免费馅饼 Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 1176 免费馅饼(数塔类型)
http://acm.hdu.edu.cn/showproblem.php?pid=1176 免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU 1176 免费馅饼(记忆化搜索)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDU 1176 免费馅饼
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1176 免费馅饼(数字三角形)
免费馅饼 Problem Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉 ...
随机推荐
- flashplayer
http://www.adobe.com/support/flashplayer/downloads.html
- UINavigationbar/UINavigationItem/UITabBar/UITabButton/UITabBarItem粑粑粑粑~
看着标题是不是乱的一塌糊涂...... . 在开发中,你非常可能就理不清这些关系,刚好闲的蛋疼,来整理一下吧. 一.UINavigationBar.UINavigationItem.UIBarButt ...
- PHP和Java的主要区别有哪些?哪个最适合Web开发语言?
一.前言 PHP和Java都是现在比较流行的二种编程语言. 对于许多新手来说,都会思考如果学的时候,该学哪种语言呢?下面这篇文章给大家整理两者的区别以及一些选择建议,一起来看看吧. 二.简介 PHP与 ...
- POJ1328 Radar Installation 【贪心·区间选点】
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 54593 Accepted: 12 ...
- nginx日志统计流量
cat access.log |awk '{sum+=$10} END {print sum/1024/1024/1024}' $10是nginx字段bytes_sent 字段,根据自己的日志格式修改 ...
- 教你用squid做CDN把公司做到上市
我们都知道CDN(内容分发网络)是用来给网站加速用的,通过在现有的Internet中增加一层新的网络架构,将网站的内容发布到最接近用户的网络的“边缘”,使用户可以就近取得所需的内容,以提高用户访问网站 ...
- is_callable — 检测参数是否为合法的可调用结构
说明 bool is_callable ( callable $name [, bool $syntax_only = false [, string &$callable_name ]] ) ...
- mapreduce学习资料
http://blog.csdn.net/tianjun2012/article/category/6794531 http://blog.csdn.net/tianjun2012/article/d ...
- Redis源码阅读-Adlist双向链表
Redis源码阅读-链表部分- 链表数据结构在Adlist.h Adlist.c Redis的链表是双向链表,内部定义了一个迭代器. 双向链表的函数主要是链表创建.删除.节点插入.头插入.尾插入. ...
- Java Web开发笔记
问题: 读取资源文件问题 servletContext.getRealPath() servletContext.getResouce().getPath() setvletContext.getRe ...