随笔分类 -  递归递推

递归输出图形
摘要:以前都是用for循环解决这类题目的。。用递归输出真的是太方便了。递归输出正方形:View Code #include <stdio.h>#include <string.h>#include <algorithm>#include <stdlib.h>#include <math.h>#include <algorithm>#include <vector>#include <queue>#include <deque>#include <stack>#include < 阅读全文

posted @ 2012-02-29 15:22 more think, more gains 阅读(461) 评论(0) 推荐(0)

递归
摘要:输入4398,然后输出‘4’ ‘3’ ’9‘ ’8‘。。。。可以利用递归的性质#include <stdio.h>#include <string.h>#include <stdlib.h>void fun(int x ){ if (x == 0) { return ; } else fun(x / 10); printf("%c\n",x % 10 + '0');}int main( ){ int a, b; while (scanf("%d",&a) != EOF) { fun(a); } 阅读全文

posted @ 2011-08-12 18:47 more think, more gains 阅读(165) 评论(0) 推荐(0)

递归 DFS
摘要:#include <stdio.h>#include <string.h>#include <stdlib.h>int sum = 0;char ch[3] = {'L', 'R','P'};void DFS(int x, int n, int t ){ int i; if (n == t) { sum += x; return ; } for (i = 0; i < 3; i++) if( ch[i] == 'L') DFS(2 * x , n + 1, t); else if ( ch 阅读全文

posted @ 2011-08-11 17:02 more think, more gains 阅读(223) 评论(0) 推荐(0)

递归 生成全排列
摘要:#include <stdio.h>#include <string.h>int a[20], N;void fun(int n, int r){ int i, j, flag; if( r == n) { for(i = 0; i < n; i++) printf("%d ",a[i]); puts(""); return ; } else { for (i = 1; i <= n; i++) { flag = 1; for(j = 0; j < r; j++) if ( i == a[j] ) flag = 阅读全文

posted @ 2011-08-11 16:58 more think, more gains 阅读(148) 评论(0) 推荐(0)

导航