C语言中递归的实例
来源:互联网 发布:手机淘宝抢购如何刷新? 编辑:程序博客网 时间:2024/06/16 16:54
李白打酒
#include <stdio.h>
int count = 0;
void libai(int store, int flower, int alco, int pre, char *ch, int index)
{
if(store == 0 && flower == 0)
{
if (alco == 0 && pre == 0)
{
int i = 0;
for (i = 0; i < 15; i++)
{
printf ("%c", ch[i]);
}
printf ("\n");
count++;
}
return ;
}
if (store > 0)
{
ch[index] = 'a';
libai(store-1, flower, alco*2, 1, ch, index+1);// 1代表碰到的是店
}
if (flower > 0)
{
ch[index] = 'b';
libai(store, flower-1, alco-1, 0,ch, index+1);// 0代表碰到的是花
}
}
void libai2(int alco, int store, int flower)
{
if (store > 5 || flower > 10)
return;
if (store == 5 && flower == 9)
{
if (alco == 1)
count++;
return ;
}
libai2(alco*2, store+1, flower);
libai2(alco-1, store, flower+1);
}
int main()
{
//libai2(2, 0, 0);
char ch[20];
libai(5, 10, 2, -1, ch, 0);
printf ("%d\n", count);
return 0;
}
- C语言中递归的实例
- C语言函数的递归和调用实例分析
- 递归算法以及C语言实例分析
- 对C语言中递归算法的分析
- iOS中C语言的递归求阶乘
- C语言中自我递归的几个例子
- c语言中递归函数真的好吗?
- 汉诺塔递归的c语言实现(递归)
- C语言里的递归
- C语言函数的递归
- c语言----函数的递归
- IOS成长中 C语言之递归
- 递归实例——C语言实现全排列
- C语言-数据结构-递归求解实例-8皇后问题
- C语言中动态数组的构造实例
- c语言中关于可变参数的一个用法实例
- C语言中控制printf的打印颜色实例…
- C语言中重要函数的简要分析及实例
- 浅谈最短路中的Bellman–Ford 算法 (SPFA
- 集束搜索(Beam Search Algorithm )
- linux下重启oracle
- ionic之AngularJS扩展功能属性
- Python数据类型 之 tuple
- C语言中递归的实例
- git笔记
- 【数据库基础】数据库完整性控制-触发器
- App权限更改导致应用重启(华为手机)
- 不少程序员都会碰到的三个面试题
- TensorFlow实战:Chapter-6(CNN-4-经典卷积神经网络(ResNet))
- 数组数列
- DataGrip真心不好用!
- JavaScript 闭包