恒邪

2014年3月17日 #

[练习] dfs输出全排列

摘要: 代码:#include #include using namespace std;int visit[11],num[11];int n;void dfs(int depth){ if(depth>n)//注意是大于号,不是大于等于,因为在等于的时候num[depth]还没有赋值 { for(int j=1;j>n) { memset(visit,0,sizeof(visit)); dfs(1); }}另一种写法,只改动了dfs函数#include #include using namespace std;int visit[1... 阅读全文

posted @ 2014-03-17 20:59 恒邪 阅读(165) 评论(0) 推荐(0) 编辑

[蓝桥杯历届试题] 第39级台阶

摘要: 题目描述: 小明刚刚看完电影《第39级台阶》,离开电影院的时候,他数了数礼堂前的台阶数,恰好是39级! 站在台阶前,他突然又想着一个问题: 如果我每一步只能迈上1个或2个台阶。先迈左脚,然后左右交替,最后一步是迈右脚,也就是说一共要走偶数步。那么,上完39级台阶,有多少种不同的上法呢?输出格式:输出一个整数解题思路:不用管是左脚还是右脚迈,只要走的步数是偶数即可。递归的思想。代码(两种方法):#include using namespace std;int total=0;/*int ss(int num,int step){ if(num39) return 0; if(num==39&am 阅读全文

posted @ 2014-03-17 19:08 恒邪 阅读(858) 评论(0) 推荐(0) 编辑

导航