10个台阶,一次一步,2步或者3步,有多少可能
f(N) = f(N-1) +f(N-2)+f(N-3)
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
void main() {
struct stack mystack;
init(&mystack);
int f1 = 1;
int f2 = 2;
int f3 = 4;
int last = 0;
for (int i = 3; i < 10; i++) {
int f4 = 0;
push(&mystack,f1);
push(&mystack, f2);
push(&mystack, f3);
while (!isempty(&mystack) ){
f4 += gettop(&mystack);
pop(&mystack);
}
f1 = f2;
f2 = f3;
f3 = f4;
last = f4;
}
printf("%d", last);
/*int f1 = 1;
int f2 = 2;
int f3 = 4;
int f4 = 0;
for (int i = 3; i < 10;i++) {
f4 = f3 + f2 + f1;
f1 = f2;
f2 = f3;
f3 = f4;
}
printf("%d", f4);*/
system("pause");
}
//#define N 10
//int get(int n) {
// if (n == 1) {
// return 1;
//
// }
// else if (n==2){
// return 2;
// }
// else if (n == 3) {
// return 4;
// }
// else {
// int num = get(n - 1) + get(n - 2) + get(n - 3);
// return num;
// }
//}
//
//
//
//void main1() {
// int a[N] = { 1,2,4 };
// for (int i = 3; i < N; i++) {
// a[i] = a[i - 1] + a[i - 2] + a[i - 3];
// }
// printf("%d", a[9]);
// printf("\n%d", get(10));
//
// system("pause");
//}