HDU 3455 Leap Frog 2016-09-12 16:34 43人阅读 评论(0) 收藏
Leap Frog
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 676 Accepted Submission(s): 244
xn where Jack or Jill may stand. Jill initially starts at position x1, Jack initially starts at position x2, and their goal is to reach position xn.Determine the minimum number of jumps needed until either Jack or
Jill reaches the goal. The two players are never allowed to stand at the same position at the same time, and for each jump, the player in the rear must hop over the player in the front.
xn<= 1000000. The end-of-fi le is denoted by a single line containing "0".
6
3 5 9 12 15 17
6
3 5 9 12 30 40
3
-1
题目的意思是初始第一个点和第二个点有两个人,人每次最多前进10步,两人轮番前进,每次是后面的人跳到前面的人的前面,,问任意一人走到最后他一个点最少多少步?
本来我们如果开dp[i][j]保存两个人的位置,题目很简单了,但是n有100000,数组开不下,我们发现每次最多走十步,那就是说只要取i之前10步以内的数就好
于是定义dp[10][100000],dp[i][j]为一个人在j位置骂另一个人在他左边i个点。
代码如下
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f int dp[15][100005];
int a[100005];
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
for(int i=1; i<=n; i++)
scanf("%d",&a[i]);
memset(dp,-1,sizeof(dp));
dp[1][2]=0;
for(int i=3; i<=n; i++)
{
for(int j=1; j<=10; j++)
{
if(i-j<1)
break;
if(a[i]-a[i-j]<=10)
{
for(int k=j+1; k<=10; k++)
{
if(i-k<1)
break;
if(a[i]-a[i-k]<=10)
{
if(dp[j][i]==-1&&dp[k-j][i-j]!=-1)
dp[j][i]=dp[k-j][i-j]+1;
else if(dp[k-j][i-j]!=-1)
dp[j][i]=min(dp[j][i],dp[k-j][i-j]+1);
}
}
} }
}
int ans=inf;
for(int i=1; i<=10; i++)
{
if(dp[i][n]!=-1)
ans=min(ans,dp[i][n]);
}
if(ans==inf)
printf("-1\n");
else
printf("%d\n",ans);
} return 0;
}
HDU 3455 Leap Frog 2016-09-12 16:34 43人阅读 评论(0) 收藏的更多相关文章
- Help Me with the Game 分类: POJ 2015-06-29 16:34 17人阅读 评论(0) 收藏
Help Me with the Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3706 Accepted: ...
- winform 解决界面闪动、提升加载速度 分类: WinForm 2015-02-03 16:34 161人阅读 评论(0) 收藏
说明: 从一个技术交流群里获得,经验证效果不错. //作用 加快界面加载 protected override CreateParams CreateParams { ...
- iOS自定义字体及类目 分类: ios技术 2015-05-15 16:34 195人阅读 评论(0) 收藏
1:获取字体文件 从各种渠道下载字体文件ttf, 网站或者从别的ipa里扣出来.(以fzltxh.ttf为例) 2:将fzltxh.ttf文件拷贝到工程中 3:在Info.plist中添加项: Fon ...
- Hdu2204 Eddy's爱好 2017-06-27 16:11 43人阅读 评论(0) 收藏
Eddy's爱好 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Subm ...
- HRBUST1315 火影忍者之~大战之后 2017-03-06 16:14 54人阅读 评论(0) 收藏
火影忍者之-大战之后 经历了大战的木叶村现在急需重建,人手又少,所以需要尽可能多的接受外来的任务,以赚取报酬,重建村庄,假设你现在是木叶的一名高级忍者,有一大堆的任务等着你来做,但毕竟个人时间有限,所 ...
- one recursive approach for 3, hdu 1016 (with an improved version) , permutations, N-Queens puzzle 分类: hdoj 2015-07-19 16:49 86人阅读 评论(0) 收藏
one recursive approach to solve hdu 1016, list all permutations, solve N-Queens puzzle. reference: t ...
- hdu 1052 (greedy algorithm) 分类: hdoj 2015-06-18 16:49 35人阅读 评论(0) 收藏
thanks to http://acm.hdu.edu.cn/discuss/problem/post/reply.php?action=support&postid=19638&m ...
- hdu1171 Big Event in HDU(01背包) 2016-05-28 16:32 75人阅读 评论(0) 收藏
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1503, LCS variants, find a LCS, not just the length, backtrack to find LCS, no extra markup 分类: hdoj 2015-07-18 16:24 139人阅读 评论(0) 收藏
a typical variant of LCS algo. the key point here is, the dp[][] array contains enough message to de ...
随机推荐
- iKcamp|基于Koa2搭建Node.js实战(含视频)☞ 规范与部署
沪江CCtalk视频地址:https://www.cctalk.com/v/15114923889450 规范与部署 懒人推动社会进步. 本篇中,我们会讲述三个知识点 定制书写规范 开发环境运行 如何 ...
- delphi实现两个目录路径的链接
filepath := PathJoin(['C:', 'path1', 'path2\', 'a.doc']); // filepath = 'C:\path1\path2\a.doc' 代码: f ...
- while and for 2
public class TestWhileAndFor2 { /** * 九九乘法表 * 1!+2!+3!+....+10!=? * */ public static void main(Strin ...
- Ansible develop module
def cnf(action,configs,path): message = "Modify %s\n" %path changed = False if action == & ...
- shell脚本通过expect脚本实现自动输入密码(使用expect)
背景:在远程文件下载时,需要输入对方的服务器密码,shell不支持交互输入内容,可以用下面两种方式实现 一.在shell脚本中嵌入expect来实现密码输入 expect是一个自动交互功能的工具. ...
- sibling
sibling 英 ['sɪblɪŋ] 美 ['sɪblɪŋ] 名词. 兄,弟,姐,妹网络. 兄弟,兄弟姐妹,同胞变形. 复数:siblings
- 安卓机在按HOME键时,UNITY触发的APPLICATION_PAUSE事件
安卓机在按HOME键时,UNITY触发的APPLICATION_PAUSE事件 此时安卓程序会返回,在这一瞬间,程序可以通过SOCKET发送数据包给服务器告知, 经测试在这短暂的时间内,这个数据包能发 ...
- Petya and Graph(最小割,最大权闭合子图)
Petya and Graph http://codeforces.com/contest/1082/problem/G time limit per test 2 seconds memory li ...
- C#中货币类型和数值类型、字符串类型的转化
1.定义textbox的数据 private void Form1_Load(object sender, EventArgs e) { this.textBox1.Text = String.For ...
- python之多线程队列
# 一共有以下3种队列# 1.先进先出# 2.后进先出# 3.存储数据的时候可设置优先级的队列,设置不同的优先级,取的时候按照优先级的顺序来取 下面介绍一下队列的方法,如果要使用队列,则需要导入一个模 ...