了断局

题目大意:

该数列为Tribonacci numbers: a(n) = a(n-1) + a(n-2) + a(n-3) for n >= 3 with a(0) = a(1) = 0 and a(2) = 1.

代码实现:

预处理前100项数存入long long数组里.

代码:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e2+10;
long long s[N];
int main()
{
    int n;
    s[1] = 0;
    s[2] = 1;
    s[3] = 1;
    for(int i = 4; i <= 100; i++) {
        s[i] = s[i-1] + s[i-2] + s[i-3];
    }
	while(cin>>n) {
		cout<<s[n]<<endl;
	}
	return 0;
}