[001] leap_stage
[Description] There is a number in each stages that indicates the most stages you can leap up. Now, giving an array which represents one kind of stair, please return if you can leap to the last stage, true if ok and vice versa.
e.g. stair[] = {4,3,1,0,2,1,0} return true;
stair[] = {2,1,0,4,3,1,0} return false;
[Thought] think about: what condition it would be true and false in current stair[0]? how to recursively call itself?
[Implementation] C code:
#include<stdio.h> int leapStage(int stair[], int size)
{
int i;
// if current stage number is zero, false, of course!
if(stair[] == )
{
return ;
}
// if current stage number indicate that we can jump over last stage, true.
else if(stair[] >= size-)
{
return ;
}
// try each way while can't touch the last stages.
for(i = stair[]; i>; i--)
{
// if there is one way can do it, true.
if(leapStage(stair+i, size-i))
{
return ;
}
}
// after try all the way, can't get it.
return ;
} int main()
{
int i;
int stair[]={,,,,,,};
int size=sizeof(stair)/sizeof(stair[]);
for(i=; i<size; i++)
{
printf("%d, ",stair[i]);
}
if(leapStage(stair,size))
{
printf(" is true!\n");
}
else
{
printf(" is false!\n");
}
}
[001] leap_stage的更多相关文章
- swift 001
swift 001 = 赋值是没有返回值的 所以 int a=10; int b=20; if(a=b){ printf("这个是错误的"); } swift 中的模运算 是支 ...
- [SDK2.2]Windows Azure Virtual Network (4) 创建Web Server 001并添加至Virtual Network
<Windows Azure Platform 系列文章目录> 在上一章内容中,笔者已经介绍了以下两个内容: 1.创建Virtual Network,并且设置了IP range 2.创建A ...
- 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数001·3D函数
<zw版·Halcon-delphi系列原创教程> Halcon分类函数001·3D函数 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“proce ...
- Android 开发错误信息001
Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessExceptio ...
- python解无忧公主的数学时间编程题001.py
python解无忧公主的数学时间编程题001.py """ python解无忧公主的数学时间编程题001.py http://mp.weixin.qq.com/s?__b ...
- php大力力 [005节] php大力力简单计算器001
2015-08-22 php大力力005. php大力力简单计算器001: 上网看视频,看了半天,敲击代码,如下: <html> <head> <title>简单计 ...
- php大力力 [001节]2015-08-21.php在百度文库的几个基础教程新手上路日记 大力力php 大力同学 2015-08-21 15:28
php大力力 [001节]2015-08-21.php在百度文库的几个基础教程新手上路日记 大力力php 大力同学 2015-08-21 15:28 话说,嗯嗯,就是我自己说,做事认真要用表格,学习技 ...
- Web前端学习笔记(001)
....编号 ........类别 ............条目 ................明细....................时间 一.Web前端学习笔记 ...
- 001 The Hello World In Csharp
C#是面向对象编程语言,语法和JAVA非常相似.接下来让我们看一下C#的Hello world. //001.cs using System; public class Hello { public ...
随机推荐
- jquery弹出层开源框架layer
高度自适应参考:layer.open如何让高度自适应? 高度自适应修改layer.js代码如下: r.iframeAuto = function(e) { if (e) { var t = r.get ...
- 第190天:js---String常用属性和方法(最全)
String常用属性和方法 一.string对象构造函数 /*string对象构造函数*/ console.log('字符串即对象');//字符串即对象 //传统方式 - 背后会自动将其转换成对象 / ...
- Spring Boot 初步小结
Spring Boot 是一种开发模式,不涉及任何新的技术 1.了解自动配置的原理 2.常用application.yml文件的配置项 3.Spring Boot 及 第三方提供的各种 starter ...
- 高斯消元模板(pascal)
洛谷P3389评测 program rrr(input,output); const eps=1e-8; var a:..,..]of double; n,i,j,k:longint; t:doubl ...
- bzoj1912【Apio2010】patrol 巡逻
题解: 显然需要分类讨论了,首先理解k==0即原图时按照dfs序来说 , 每条边至少走两次: k==1,相当于可以省去dfs回溯时第二次走过某条路径的浪费,所以答案是k==0的答案-直径 : k==2 ...
- opencv 获取摄像头图像
http://www.cnblogs.com/epirus/archive/2012/06/04/2535190.html #include "stdafx.h" #include ...
- Linux下的tar压缩解压缩命令详解(转)
tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个.下面的 ...
- MFC之ListCtrl动态添加按钮
先上效果图: 图中用了一个CListCtrl插件,隐藏了网格线(LVS_EX_GRIDLINES). 添加了“删除”按钮(按钮上贴了图片),选中哪一行则显示在哪一行. 有两种方式创建按钮,一种是直接根 ...
- Codeforces Round #384 (Div. 2) A B C D dfs序+求两个不相交区间 最大权值和
A. Vladik and flights time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- python函数的输入参数
http://note.youdao.com/noteshare?id=c2a0a39ee3cae09a62dcbc9f96d04b56