递归法
#include
using namespace std;
void Merge(int r[],int r1[],int b,int m,int e){
int i=b;
int j=m+1;
int k=b;
while((i<=m)&&(j<=e)){
if(r[i]<=r[j]){
r1[k]=r[i];
i++;
k++;}
else{
r1[k...
分类:
编程语言 时间:
2015-03-12 11:32:51
阅读次数:
179
样题:sdut2015寒假结训赛开始我还以为是用背包来做,但是写完了代码,怎么写就是不对,并且在实现的时候确实有点地方我用背包的算法描述不了!后来查到可以用:递归 或者 母函数算法!比赛时曾考虑过用递归来实现,但没有推导出来,后来发现别人的博客里面写着“整数划分问题”应该在讲解递归的时候就该学会了。...
分类:
其他好文 时间:
2015-03-06 18:29:32
阅读次数:
176
??
1.16 迭代法计算B的N次方
先是Java实现的递归法和迭代法:
public class Test {
public static void main(String args[]){
int ex,ey;
ex = expt(122,4);
ey = expt_iter(122, 4, 1);
System.o...
分类:
其他好文 时间:
2015-01-20 09:02:53
阅读次数:
167
数组面试题#includeusing namespace std;//数组求和int sum(int *a, int n){ return n == 0 ? 0 : sum(a, n - 1) + a[n - 1];}//递归法数组求和int sum2(int *a, int n){ int s =...
分类:
编程语言 时间:
2014-12-28 23:35:37
阅读次数:
270
题目
Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,3,2].
解答
中序遍历二叉树。
递归法...
分类:
其他好文 时间:
2014-12-21 15:20:58
阅读次数:
178
八皇后问题,是19世纪著名的数学家高斯在1850年提出的:在8×8格的国际象棋盘上摆放8个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行、同一列、同一斜线上,试问有多少种摆法?高斯先生给出的答案是“76”种,实际是76种吗? 八皇后问题是回溯算法的典型应用,但是本文提供递归的求法。 ...
分类:
其他好文 时间:
2014-12-16 22:19:48
阅读次数:
302
本题一般使用递归法+记忆搜索得到答案。
这里使用一种新的方法:
根据题目特点必须要从高到底,那么可以把所有值排序,然后从最小值的方格开始搜索,每次搜索相邻的四个方格是否可行,然后存储最大值;这样不使用递归也直接得到答案了。...
分类:
其他好文 时间:
2014-12-09 12:24:00
阅读次数:
196
#includeusing namespace std;/*递归法*//*递归法会在函数中调用自己,注意结束条件,避免无限循环,递归法的原理是压栈出栈*//*例1:f(n)=n! 则f(n)=f(n-1)*n*/int f1(int n){ if (n > n; cout > n; ...
分类:
编程语言 时间:
2014-11-25 22:43:04
阅读次数:
196
递归法(TLE代码): 1 class Solution { 2 public: 3 int climbStairs(int n) { 4 if(n==0) 5 return 1; 6 if(n3时,要返回的是n-1和n-2所要返回的数...
分类:
其他好文 时间:
2014-11-24 20:25:30
阅读次数:
221
#include
#include
#include
#include
using namespace std;
/*
*循环赛日程表(递归法)
*/
void Copy(int **map,int sr,int sl,int dr,int dl,int k)
{
for (int i = 0; i < k; i++)
{
for (int j = 0; j < k; j++)
{...
分类:
其他好文 时间:
2014-11-12 23:08:57
阅读次数:
1062