ACM_递归专项系列
acceptedwwh
当代大学生,阳光开朗,乐于交往和求知!
展开
-
hanoi问题
#include #include using namespace std;int counter = 1;int move(int n,int a1,int b1,int c1){ getchar(); printf("count=%d -> ", counter++); printf("%d %c %c %c\n", n, a1, b1, c1原创 2012-09-15 18:48:59 · 837 阅读 · 0 评论 -
递归法求幂
#include #include #include using namespace std;int myPow(int m, int n){ int temp; if(0 == n){ return 1; } if(1 == n){ return m; } if(n%2 == 0){ temp =原创 2012-09-22 22:34:19 · 1504 阅读 · 0 评论 -
整数的划分
#include using namespace std;int k, n;long r;void backtrack(long dep, long prev, long n){ long m; if(dep == k){ if(n >= prev){ r++; return ; }原创 2012-09-22 19:19:37 · 758 阅读 · 0 评论 -
二分查找(递归与非递归)
#include #include #include #include #include #include using namespace std;int temp = -1;const int maxn = 10000;int bsearch2(int *t, int b, int e, int val){ int mid =(b+e)/2; if(t[mi原创 2012-11-17 10:19:34 · 943 阅读 · 0 评论 -
POJ 1579
#include #include using namespace std;const int maxn = 55;int f[maxn][maxn][maxn];int w(int a, int b, int c) { if(a <= 0 || b <= 0 || c <= 0) { return 1; } if(a > 20 || b > 2原创 2012-12-05 23:43:03 · 1115 阅读 · 2 评论 -
POJ1664(放苹果,感觉比较有意思)
#include#include #include using namespace std;int counter(int x,int y) { if(y==1 || x==0) { return 1; } if(x<y) return counter(x, x); return counter(x,y-1) + counter(x-y,y);}int原创 2013-02-18 23:32:12 · 893 阅读 · 0 评论