【算法系列学习】[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 ...
随机推荐
- Linux 修改时区 不用重启
1.cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 2.使用tzselect命令,根据提示选择 3.使用date查看是否修改正确 4.运行hwc ...
- MySQL常用函数及日期
一.数学函数 数学函数主要用于处理数字,包括整型.浮点数等. ABS(x) 返回x的绝对值 SELECT ABS(-1) -- 返回1 CEIL(x),CEILING(x) 返回大于或等于x的最小整数 ...
- 如何在container中编译dotnet的eShopOnContainers
准备的软件 问题 Image下载问题 以下就是为啥要有最后一个软件(我是使用版): SQLSever for Linux 内存需求 需要编译Image 成功搞定 参考 Welcome to t ...
- c#XML操作类的方法总结
using System.Xml;using System.Data; namespace DotNet.Utilities{ /// <summary> /// Xml的操作 ...
- supervisor安装配置
1.安装 下载:https://codeload.github.com/Supervisor/supervisor/zip/3.1.3 2.安装 .zip cd supervisor- python ...
- Android应用程序更新并下载
创建一个新类,名为UpdateManager,代码如下: package com.af.service; import java.io.BufferedReader; import java.io.F ...
- pl sql 查询显示乱码解决方法——设置环境变量NLS_LANG
用oracle进行查询的时候,有的时候会出现查询结果为乱码的情况,此时要设置一个环境变量NLS_LANG. 此变量的值如何获得呢?运行下面sql语句就可以获得: select userenv('lan ...
- MyBatis 源码分析——动态SQL语句
有几年开发经验的程序员应该都有暗骂过原生的SQL语句吧.因为他们不能一句就搞定一个业务,往往还要通过代码来拼接相关的SQL语句.相信大家会理解SQL里面的永真(1=1),永假(1=2)的意义吧.所以m ...
- 查看mac上的隐藏文件
打开终端敲入(最好是复制),这样就可以隐藏隐藏文件: defaults write com.apple.finder AppleShowAllFiles -boolean false ; killal ...
- [转]html中offsetTop、clientTop、scrollTop、offsetTop各属性介绍
HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth scrollHeight: 获取对象的滚动高度. scrollLeft:设置或获取位于对 ...