Title Requirements:
Enhanced Fibonacci sequence: f[i] = i (i <= 3); F[i] = F[i-1] + f[i-2] + f[i-3] (i >= 4), Input n (1<=n&&n<=30), output F[N]. Topic idea: Define array A, give directly a[1]=1, a[2]=2, a[3]=3, define Loop Loop 30 times f[1] to f[30], enter the value of N, direct output F[N]. Detail handling: Because the value of n is very small, the value of all F[n] is calculated directly, while the while function is used to output f[n when the value of n is entered, which prevents time-outs.
#include <bits/stdc++.h>
using namespace std;
int main ()
{ long a[35];
int i,n;
a[1]=1;a[2]=2;a[3]=3;
for (i=4;i<=30;i++)
a[i]=a[i-1]+a[i-2]+a[i-3];
while (Cin>>n)
{ cout<<a[n]<<endl;
}
return 0;
}
Sentiment: For a good understanding of the problem, to pay attention to the details of the treatment, to prevent data overflow, too many operations, timeouts and other problems.