HDU1176 免费馅饼 —— DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1176
免费馅饼
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 53204 Accepted Submission(s): 18681

为了使问题简化,假设在接下来的一段时间里,馅饼都掉落在0-10这11个位置。开始时gameboy站在5这个位置,因此在第一秒,他只能接到4,5,6这三个位置中其中一个位置上的馅饼。问gameboy最多可能接到多少个馅饼?(假设他的背包可以容纳无穷多个馅饼)
提示:本题的输入数据量比较大,建议用scanf读入,用cin可能会超时。
5 1
4 1
6 1
7 2
7 2
8 3
0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e5+; int a[MAXN][], dp[MAXN][];
int n; int main()
{
while(scanf("%d", &n) &&n)
{
ms(a, );
for(int i = ; i<=n; i++)
{
int x, t;
scanf("%d%d", &x, &t);
a[t][x]++;
} ms(dp,-);
dp[][] = ;
int ans = -INF;
for(int i = ; i<=1e5; i++) //时间
for(int j = ; j<=; j++) //地点
{
if(dp[i-][j]!=-) //留在原地
dp[i][j] = max( dp[i][j], dp[i-][j]+a[i][j] );
if(j!= && dp[i-][j-]!=-) //从左边走过来
dp[i][j] = max( dp[i][j], dp[i-][j-]+a[i][j] );
if(j!= && dp[i-][j+]!=-) //从右边走过来
dp[i][j] = max( dp[i][j], dp[i-][j+]+a[i][j] ); ans = max(ans, dp[i][j]);
} printf("%d\n", ans);
}
}
HDU1176 免费馅饼 —— DP的更多相关文章
- HDU1176:免费馅饼(DP)
Problem Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁 ...
- kuangbin专题十二 HDU1176 免费馅饼 (dp)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1176免费馅饼 DP数塔问题转化
L - 免费馅饼 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- 解题报告 HDU1176 免费馅饼
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu1176 (免费馅饼)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu-1176免费馅饼
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu1176免费馅饼(动态规划,数塔)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU - 1176 免费馅饼 DP多种状态转移
免费馅饼 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内.馅饼如果掉在了 ...
- HDU1176免费馅饼(DP)
都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内.馅饼如果掉在了地上当然就 ...
随机推荐
- hihoCoder#1141 二分·归并排序之逆序对
原题地址 又是一道WA成狗的题,最后发现原来是结果溢出了.. 代码: #include <iostream> #include <cstring> using namespac ...
- 数列分段Section II(二分)
洛谷传送门 输入时处理出最小的答案和最大的答案,然后二分答案即可. 其余细节看代码 #include <iostream> #include <cstdio> using na ...
- PHP字符串的替换(preg_replace)
/* 正则表达式 preg_replace() */ $str = array( "如果没有一些http://www.abc.com特殊的<b>替换</b>需5求( ...
- [Baltic2007]序列问题Sequence
Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 1002 Solved: 535[Submit][Status][Discuss] Descriptio ...
- 2887 Big String
splay瞎搞一下,正解是分块数组或分块链表,但是学不会啊! #include<cstdio> #include<cstdlib> #include<iostream&g ...
- THUPC2018看题总结
THUPC2018看题总结 #6387. 「THUPC2018」绿绿与串串 / String 据说是签到题啊. 首先根据题目的意思,我们发现如果能找到那个最后一次选择的对称轴岂不是美滋滋. 自然地,我 ...
- Max Sum Plus Plus-HDU1024(dp)
Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To b ...
- uva 662
dp +路径输出 #include <cstdio> #include <cstdlib> #include <cmath> #include <stack& ...
- 【TFS 2017 CI/CD系列 - 01】-- Agent篇
一.环境要求: PowerShell 3.0 或者更高版本 VS2015或者更高版本 二.下载Agent: 用浏览器打开TFS,[Settings]--> [Agent Pools]--> ...
- Java生成验证码并进行验证(转)
本文转自http://blog.csdn.net/worm0527/article/details/51030864 一.实现思路 使用BufferedImage用于在内存中存储生成的验证码图片 使用 ...