【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 G - 免费馅饼
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 - 免费馅饼的更多相关文章
- [kuangbin带你飞]专题十二 基础DP1
ID Origin Title 167 / 465 Problem A HDU 1024 Max Sum Plus Plus 234 / 372 Problem B HDU 1 ...
- 【算法系列学习】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 ...
- 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 F - Piggy-Bank 【完全背包问题】
https://vjudge.net/contest/68966#problem/F http://blog.csdn.net/libin56842/article/details/9048173 # ...
- 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 E - Super Jumping! Jumping! Jumping!
https://vjudge.net/contest/68966#problem/E http://blog.csdn.net/to_be_better/article/details/5056334 ...
- 【算法系列学习】状压dp [kuangbin带你飞]专题十二 基础DP1 D - Doing Homework
https://vjudge.net/contest/68966#problem/D http://blog.csdn.net/u010489389/article/details/19218795 ...
- 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 C - Monkey and Banana
https://vjudge.net/contest/68966#problem/C [参考]http://blog.csdn.net/qinmusiyan/article/details/79862 ...
- 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 B - Ignatius and the Princess IV
http://www.cnblogs.com/joeylee97/p/6616039.html 引入一个cnt,输入元素与上一个元素相同,cnt增加,否则cnt减少,当cnt为零时记录输入元素,因为所 ...
- [ An Ac a Day ^_^ ] [kuangbin带你飞]专题十二 HDU 1176 免费馅饼
题意: 中文题意不解释…… 思路: 先把x,T存到矩阵里 然后像数塔一样从最底层走一边就行了 dp[i][j]代表在时间为j时 第i个位置最多能吃到多少个馅饼 最后输出第0时刻的5位置的馅饼数量就好了 ...
- [kuangbin带你飞]专题十 匹配问题
A-L 二分匹配 M-O 二分图多重匹配 P-Q 二分图最大权匹配 R-S 一般图匹配带花树 模板请自己找 ID Origin Title 61 / 72 Problem A HD ...
随机推荐
- (19)IO流之字符流FileReader和FileWriter,缓冲字符流---缓冲输入字符流BufferedReader和缓冲输出字符流BufferedWriter
字符流,读取的文件是字符的时候,有两个基类一个是Reader,一个是Writer这有点拟人的感觉,人直接看懂的是文字 字符流 字节流:读取的是文件中的二进制字节流并不会帮你转换成看的懂得字符 字符流: ...
- (14)jdk1.5开始的一些新特性:静态导入,增强for循环,可变参数,自动装箱/拆箱,枚举类型
Jdk1.5新特性之静态导入 jdk1.5新特性值静态导入 静态导入的作用:简化缩写 静态导入的作用:可以作用一个类的所有静态成员. 静态导入的格式:import static 包名.类名.静态的成员 ...
- java操作txt文本(一):遇到指定字符换行
想法由来:有时查看网页源代码的css文件内容,竟是恼人的压缩后代码(不换行),如下图所示-- 它的可读性很差,所以写了下面这个简单的程序,实现自动换行. 适用条件:遇到指定字符换行(本例中遇到'}'换 ...
- Sublime安装Package Control插件
一.简易安装 打开Sublime text的console.打开console的快捷时ctrl+,或者在菜单栏点击View->Show Sonsole`.打开后将下面的代码复制到console中 ...
- Struts2之Action与配置文件
一.Struts2配置文件 1.struts.properties 在学习Action之前先学下Struts2的配置文件,与Struts2相关的配置文件有好几个,常用的有Struts.xml,web. ...
- memcached参数解释及常用命令
一.执行 memcached -h 会显示所有的参数项,对应的中文解释如下: -p <num> 监听的TCP端口(默认: 11211) -U <num> 监 ...
- iwebshop里面传数组且输出
//php后台 $starttimestr = $arr[0]['forea_time']; $endtimestr = $arr[0]['end_time']; $data['starttime'] ...
- 深入浅出分析MySQL MyISAM与INNODB索引原理、优缺点、主程面试常问问题详解
本文浅显的分析了MySQL索引的原理及针对主程面试的一些问题,对各种资料进行了分析总结,分享给大家,希望祝大家早上走上属于自己的"成金之路". 学习知识最好的方式是带着问题去研究所 ...
- jquery data属性的使用
var func=function(){console.log("test")};$("div").data("test",func);$( ...
- 模式识别与机器学习—bagging与boosting
声明:本文用到的代码均来自于PRTools(http://www.prtools.org)模式识别工具箱,并以matlab软件进行实验. (1)在介绍Bagging和Boosting算法之前,首先要简 ...