回复 7楼 守护靖
若n=6,总的有13种,奇数步有6种;而按照这个算出来是7种。
#include<stdio.h> int f(int n) { int a1 = 1, a2 = 1, b1 = 0, b2 = 1, ta, tb, i; if(n < 2) return 0; for(ta = a2, tb = b2, i = 3; i <= n; i++) { ta = b1 + b2; tb = a1 + a2; a1 = a2; a2 = ta; b1 = b2; b2 = tb; } return tb; } int main() { printf("%d", f(39)); return 0; }