【算法系列学习】[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 ...
随机推荐
- Java的一些基础知识
1.do-while循环不论循环条件判断结果,至少会执行一次. 2.Javac用于Java源代码文件编译成字节码的编译器. 3.import关键字导入包. 4.Java是Sun公司与1995年退出的高 ...
- Linux块设备驱动(一) _驱动模型
块设备是Linux三大设备之一,其驱动模型主要针对磁盘,Flash等存储类设备,本文以3.14为蓝本,探讨内核中的块设备驱动模型 框架 下图是Linux中的块设备模型示意图,应用层程序有两种方式访问一 ...
- 模拟一个shuffle
之所以会想到写这么一个shuffle的例子,是因为一个需求:我需要把一个有序数组中的数据随机的打散.java代码如下, public void shuffle() { int[] arr = {1,2 ...
- (30)批处理文件.bat
批处理文件(bat) 简单的说,批处理的作用就是自动的连续执行多条命令 .编写bat处理文件可以使用记事本的方式: 常见批处理文件的命令: echo 表示显示此命令后的字符 tiltle 设置窗口的标 ...
- JS把命名空间传递给模块形式
//方法依赖 jquery 或者其他 有扩展方法 extend() 类库 例如: underscore.js 链接地址 http://underscorejs.org var app = {}; ( ...
- 强大的版本管理工具 Git
Git 简介 git 是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目.是 linux 创始人 Linus Torvalds 为了帮助管理 linux 内核开发而开发的一个开 ...
- FastDFS分布文件系统相关资料索引
FastDFS是为互联网应用量身定做的一套分布式文件存储系统,非常适合用来存储用户图片.视频.文档等文件.对于互联网应用,和其他分布式文件系统相比,优势非常明显.具体情况大家可以看相关的介绍文档,包括 ...
- python复习。知识点小记
1.对于单个字符的编码,Python提供了ord()函数获取字符的整数表示,chr()函数把编码转换为对应的字符: >>> ord('A') >>> ord('中' ...
- ActiveMQ Part 1 : 基本安装配置(windows 版本)
1. 安装启动服务 A) 首先下载并安装最新的 JDK(本文使用:jdk-8u66-windows-x64.exe) B) 从官网下载最新的安装包(本文下载版本为:http://activemq.ap ...
- Zookeeper-3.4.9 集群搭建
这里用了三台主机,系统为CentOS7 1.修改hosts #vim /etc/hosts 172.50.0.31 node1 172.50.0.34 node2 172.50.0.37 node3 ...