hdu1176——免费馅饼
来源:互联网 发布:c语言用while求次方 编辑:程序博客网 时间:2024/06/13 21:05
免费馅饼
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 26120 Accepted Submission(s): 8911
Problem Description
都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人,所以他只能在小径上接。由于gameboy平时老呆在房间里玩游戏,虽然在游戏中是个身手敏捷的高手,但在现实中运动神经特别迟钝,每秒种只有在移动不超过一米的范围内接住坠落的馅饼。现在给这条小径如图标上坐标:
为了使问题简化,假设在接下来的一段时间里,馅饼都掉落在0-10这11个位置。开始时gameboy站在5这个位置,因此在第一秒,他只能接到4,5,6这三个位置中其中一个位置上的馅饼。问gameboy最多可能接到多少个馅饼?(假设他的背包可以容纳无穷多个馅饼)
为了使问题简化,假设在接下来的一段时间里,馅饼都掉落在0-10这11个位置。开始时gameboy站在5这个位置,因此在第一秒,他只能接到4,5,6这三个位置中其中一个位置上的馅饼。问gameboy最多可能接到多少个馅饼?(假设他的背包可以容纳无穷多个馅饼)
Input
输入数据有多组。每组数据的第一行为以正整数n(0<n<100000),表示有n个馅饼掉在这条小径上。在结下来的n行中,每行有两个整数x,T(0<T<100000),表示在第T秒有一个馅饼掉在x点上。同一秒钟在同一点上可能掉下多个馅饼。n=0时输入结束。
Output
每一组输入数据对应一行输出。输出一个整数m,表示gameboy最多可能接到m个馅饼。
提示:本题的输入数据量比较大,建议用scanf读入,用cin可能会超时。
提示:本题的输入数据量比较大,建议用scanf读入,用cin可能会超时。
Sample Input
65 14 16 17 27 28 30
Sample Output
4
Author
lwg
Recommend
We have carefully selected several similar problems for you: 2084 1058 1203 1257 1421
设状态dp[t][i] 表示 第 t 秒在i位置时,所能得到的最多的馅饼数目,设xianbin[t][i]表示第t秒时i位置的馅饼数目
显然 dp[t][i] = max{ dp[t - 1][i] + xianbin[t][i], dp[t - 1][i - 1]+ xianbin[t][i], dp[t - 1][i + 1] + xianbin[t][i] }
知道这些就简单了
设状态dp[t][i] 表示 第 t 秒在i位置时,所能得到的最多的馅饼数目,设xianbin[t][i]表示第t秒时i位置的馅饼数目
显然 dp[t][i] = max{ dp[t - 1][i] + xianbin[t][i], dp[t - 1][i - 1]+ xianbin[t][i], dp[t - 1][i + 1] + xianbin[t][i] }
知道这些就简单了
#include <map>#include <set>#include <list>#include <stack>#include <vector>#include <queue>#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int xianbin[100010][15];int dp[100010][15];int main(){ int n; while (~scanf("%d", &n), n) { memset ( xianbin, 0, sizeof(xianbin) ); int x, t, c1, c2, c3; int all_time = 0; for (int i = 0; i < n; ++i) { scanf("%d%d", &x, &t); all_time = max(all_time, t); xianbin[t][x]++; } memset ( dp, 0, sizeof(dp) ); int l = 4, r = 6; for (int i = 1; i <= all_time; ++i) { for (int j = l; j <= r; ++j) { c1 = c2 = c3 = 0; c1 = dp[i - 1][j] + xianbin[i][j]; if (j > l) { c2 = dp[i - 1][j - 1] + xianbin[i][j]; } if (j < r) { c3 = dp[i - 1][j + 1] + xianbin[i][j]; } dp[i][j] = max(c1, max(c2, c3) ); } if(l > 0) { l--; } if(r < 10) { r++; } } int ans = 0; for (int i = 0; i < 11; ++i) { ans = max(ans, dp[all_time][i]); } printf("%d\n", ans); } return 0;}
0 0
- HDU1176——免费馅饼
- hdu1176——免费馅饼
- hdu1176——免费馅饼
- hdu1176——免费馅饼
- 动态规划——hdu1176免费馅饼
- hdu1176—免费馅饼(dp)
- ACM-DP之免费馅饼——HDU1176
- HDU1176免费馅饼
- HDU1176 免费馅饼
- hdu1176免费馅饼
- HDU1176 免费馅饼
- hdu1176免费馅饼
- hdu1176 免费馅饼
- HDU1176--免费馅饼
- hdu1176-免费馅饼
- hdu1176 免费馅饼
- HDU1176 免费馅饼
- hdu1176 免费馅饼
- struts中过滤器的实例
- MongoDB CRUD 基础入门
- NotificationManager和Notification的使用总结
- MySQL 修改参数
- 王立平--android:gravity与android:layout_gravity区别
- hdu1176——免费馅饼
- Android中Activity启动过程探究
- OC数据存储大集合2(手把手教你全搞定)
- android viewflipper和tabhost效率对比
- EditText的属性使用
- 提交时提示错误This Bundle is invalid.New apps and app updates submitted to the App Store must be built wit
- jquery操作复选框(checkbox)的12个小技巧总结
- VS插件介绍
- zoj3822 Domination 概率dp --- 2014 ACM-ICPC Asia Mudanjiang Regional Contest