Peace,friendhuangdachuan.blog.chinaunix.net
hdc1112_cu
全部博文(54)
2012年(2)
2011年(10)
2010年(28)
2009年(14)
fangfeic
84745676
42235992
wibnmo
hellokid
破棉袄
logicMai
aa673
zhengche
分类: C/C++
2010-12-19 09:51:00
// f(0) = 1 // f(1) = 1 // f(2) = f(1)*f(0) + f(0)*f(1) = 2 // f(3) = f(2)*f(0) + f(1)*f(1) + f(0)*f(2) = 2*1 + 1*1 + 1*2 = 5 // f(4) = f(3)*f(0) + f(2)*f(1) + f(1)*f(2) + f(0)*f(3) = 5*1 + 2*1 + 1*2 + 1*5 = 14 #include <stdio.h> int f(int n) { if (n == 0 || \ n == 1) { return 1; } int sum = 0; int i = 0; for (i =0; i<n; i++) { sum += f(i)*f(n-i-1); } return sum; } int main() { printf("%d\n", f(16)); return 1; }
// f(0) = 1 // f(1) = 1 // f(2) = f(1)*f(0) + f(0)*f(1) = 2 // f(3) = f(2)*f(0) + f(1)*f(1) + f(0)*f(2) = 2*1 + 1*1 + 1*2 = 5 // f(4) = f(3)*f(0) + f(2)*f(1) + f(1)*f(2) + f(0)*f(3) = 5*1 + 2*1 + 1*2 + 1*5 = 14 #include <stdio.h> int f(int n, int a[]) { if (a[n]) { return a[n]; } int sum = 0; int i = 0; for (i =0; i<n; i++) { sum += f(i, a)*f(n-i-1, a); } a[n] = sum; return sum; } int a[100]; int main() { a[0]=1; a[1]=1; printf("%d\n", f(16, a)); return 1; }
上一篇:双栈实现一队列/双队列实现一栈 C语言实现
下一篇:LCS(Longest Common Sequence), Java/C实现
chinaunix网友2010-12-20 16:08:05
很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com
登录 注册