https://vjudge.net/contest/68966#problem/G

正解一:

http://www.clanfei.com/2012/04/646.html

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=1e5+;
int a[][maxn];
int dp[][maxn]; bool check(int x)
{
if(x>=&&x<=)
{
return ;
}
return ;
}
int main()
{
int n,x,y,maxtime;
while(scanf("%d",&n)==&&n)
{
maxtime=-INF;
memset(a,,sizeof(a));
for(int i=;i<n;i++)
{
scanf("%d%d",&x,&y);
a[x][y]++;
maxtime=max(maxtime,y);
}
memset(dp,,sizeof(dp));
for(int i=maxtime-;i>=;i--)
{
for(int k=;k<=;k++)
{
dp[k][i]=dp[k][i+];
if(check(k-))
{
dp[k][i]=max(dp[k][i],dp[k-][i+]);
}
if(check(k+))
{
dp[k][i]=max(dp[k][i],dp[k+][i+]);
}
dp[k][i]+=a[k][i];
}
}
printf("%d\n",dp[][]);
}
return ;
}

正推

正解二:

http://blog.csdn.net/qq_32680617/article/details/51057963

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=1e5+;
int a[][maxn];
int main()
{
int n,x,y;
while(scanf("%d",&n)==&&n)
{
memset(a,,sizeof(a));
int maxtime=-INF;
for(int i=;i<n;i++)
{
scanf("%d%d",&x,&y);
maxtime=max(maxtime,y);
a[x][y]++;
}
for(int i=maxtime-;i>=;i--)
{
for(int k=;k<=;k++)
{
if(k==)
{
a[k][i]+=max(a[k][i+],a[k+][i+]);
}
else
{
a[k][i]+=max(max(a[k][i+],a[k-][i+]),a[k+][i+]);
}
}
}
printf("%d\n",a[][]);
}
return ;
}

逆推

RE:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=1e5+;
int a[][maxn];
int main()
{
int n,x,y;
while(scanf("%d",&n)==&&n)
{
memset(a,,sizeof(a));
int maxtime=-INF;
for(int i=;i<n;i++)
{
scanf("%d%d",&x,&y);
maxtime=max(maxtime,y);
a[x][y]++;
}
for(int i=maxtime-;i>=;i--)
{
for(int k=;k<=;k++)
{
if(k==)
{
a[k][i]+=max(a[k][i+],a[k+][i+]);
}
else
{
a[k][i]+=max(max(a[k][i+],a[k-][i+]),a[k+][i+]);
}
}
}
printf("%d\n",a[][]);
}
return ;
}

RE

这份代码是按逆推写的,然而不知道为什么RE,看数组也没越界.....先放在这里.....

【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 G - 免费馅饼的更多相关文章

  1. [kuangbin带你飞]专题十二 基础DP1

            ID Origin Title   167 / 465 Problem A HDU 1024 Max Sum Plus Plus   234 / 372 Problem B HDU 1 ...

  2. 【算法系列学习】DP和滚动数组 [kuangbin带你飞]专题十二 基础DP1 A - Max Sum Plus Plus

    A - Max Sum Plus Plus https://vjudge.net/contest/68966#problem/A http://www.cnblogs.com/kuangbin/arc ...

  3. 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 F - Piggy-Bank 【完全背包问题】

    https://vjudge.net/contest/68966#problem/F http://blog.csdn.net/libin56842/article/details/9048173 # ...

  4. 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 E - Super Jumping! Jumping! Jumping!

    https://vjudge.net/contest/68966#problem/E http://blog.csdn.net/to_be_better/article/details/5056334 ...

  5. 【算法系列学习】状压dp [kuangbin带你飞]专题十二 基础DP1 D - Doing Homework

    https://vjudge.net/contest/68966#problem/D http://blog.csdn.net/u010489389/article/details/19218795 ...

  6. 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 C - Monkey and Banana

    https://vjudge.net/contest/68966#problem/C [参考]http://blog.csdn.net/qinmusiyan/article/details/79862 ...

  7. 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 B - Ignatius and the Princess IV

    http://www.cnblogs.com/joeylee97/p/6616039.html 引入一个cnt,输入元素与上一个元素相同,cnt增加,否则cnt减少,当cnt为零时记录输入元素,因为所 ...

  8. [ An Ac a Day ^_^ ] [kuangbin带你飞]专题十二 HDU 1176 免费馅饼

    题意: 中文题意不解释…… 思路: 先把x,T存到矩阵里 然后像数塔一样从最底层走一边就行了 dp[i][j]代表在时间为j时 第i个位置最多能吃到多少个馅饼 最后输出第0时刻的5位置的馅饼数量就好了 ...

  9. [kuangbin带你飞]专题十 匹配问题

        A-L 二分匹配 M-O 二分图多重匹配 P-Q 二分图最大权匹配 R-S 一般图匹配带花树 模板请自己找     ID Origin Title   61 / 72 Problem A HD ...

随机推荐

  1. 简单的线性M移动平均

    最近在写Python的爬虫爬取全校学生的成绩信息和照片,发现些许问题. python的内存管理机制还没摸透,随着程序的运行,占用内存逐渐增大,料想应该是新开辟的空间未及时释放. 先研究研究算法,为比赛 ...

  2. Swiper3 的特色功能

  3. ios 个推推送集成

    个推推送总结: 个推第三方平台官网地址:http://www.getui.com/cn/index.html 首先去官网注册账号,创建应用,应用的配置信息,创建APNs推送证书上传 P12证书(开发对 ...

  4. Android开发之NavigationView的使用

    NavigationView主要是和DrawerLayout框架结合使用,来完成抽屉导航实现侧边栏 引用一段官方文档的示例代码 <android.support.v4.widget.Drawer ...

  5. 组件Prop验证

    <div id="example"> <kkk></kkk> </div> <script src="https:/ ...

  6. python运用中文注释时报错解决方法

    写了一段简单的代码,不知 为什么总是报错,后来上网查了一下才知道原因,当用中文进行注释时需要添加如下代码:# coding=utf-8          (注意:该段代码必须放在最前面才能有用,并且 ...

  7. Unity3D对弈游戏:狼吃羊游戏

    简介 中文名:狼与羊 英文名称:Wolves&Sheep 游戏类型:休闲/棋类 玩家人数:单人或双人 游戏下载:Windows.Android 游戏描述:童年时与小伙伴常玩的一种游戏,游戏简单 ...

  8. dispaly属性,position属性

    position:absolute;绝对定位相对于父元素(父元素设为relative) position:relative;相对定位相对于自己 position:fixed;固定定位相对于浏览器 di ...

  9. unity3d屏蔽Windows10输入法

    在win10上,如果安装了某些输入法(比如QQ输入法),会造成unity的键盘事件被输入法捕获而不能触发的情况.只有将输入法切换到英文状态下才能响应键盘事件. 解决办法有, 1:用户主动切换输入法,甚 ...

  10. API测试自动化——基于CDIF的SOA基本功能(实例篇)

    今天我们通过一些实例来体验一下API的自动化测试,感受一下基于CDIF的SOA的一些基本功能. 传统的测试工具在测试一个API的时候,必须手动填写这个API所需要接收的所有信息,比如一个查询航班动态的 ...