递推式:f[n]=2*f[n-2]+f[n-1]
#include <cstdio> #include <iostream> using namespace std; long long f[51]; int main() { int i,n; f[1]=1; f[2]=3; for(int i=3; i<51; i++) f[i]=f[i-1]+2*f[i-2]; cin>>n; while(cin>>n) cout<<f[n]<<endl; return 0; }
2023-11-14 11:28:22
递推式:f[n]=2*f[n-2]+f[n-1]
#include <cstdio> #include <iostream> using namespace std; long long f[51]; int main() { int i,n; f[1]=1; f[2]=3; for(int i=3; i<51; i++) f[i]=f[i-1]+2*f[i-2]; cin>>n; while(cin>>n) cout<<f[n]<<endl; return 0; }