实际就是求斐波那契数列
int numWays(int n){ if (n == 0 || n == 1) return 1; int prepre = 1; int pre = 1; int curr = 0; for (int i = 2; i <= n; i++) { curr = prepre + pre; curr %= 1000000007; prepre = pre; pre = curr; //printf("%u--%d\n", curr, i); } return curr; }
int count =0; void one(int n,int sum); void two(int n,int sum); void one(int n,int sum) { sum+=1; if (sum == n) count++; else if(sum < n) { one(n,sum); two(n,sum); } } void two(int n,int sum) { sum+=2; if (sum == n) count++; else if(sum < n) { one(n,sum); two(n,sum); } } int numWays(int n){ if (n == 0 || n == 1) return 1; int sum =0; one(n,sum); two(n,sum); return count; }