1 #include<iostream> 2 #include<iomanip> 3 //#include<bits/stdc++.h> 4 #include<cstdio> 5 #include<cmath> 6 #include<cstring> 7 #include<algorithm> 8 #include<sstream> 9 #define PI 3.14159265358979 10 #define LL long long 11 #define eps 0.00000001 12 using namespace std; 13 LL f[100]; 14 LL solve(LL x) 15 { 16 if(f[x]) return f[x]; 17 for(int i=4;i<=x;++i) 18 { 19 f[i]=f[i-1]+2*f[i-2]; 20 } 21 return f[x]; 22 } 23 int main() 24 { 25 LL T;f[1]=3,f[2]=6,f[3]=6; 26 while(cin>>T) 27 { 28 if(T==1) cout<<3<<endl; 29 else if(T==2) cout<<6<<endl; 30 else if(T==3) cout<<6<<endl; 31 else cout<<solve(T)<<endl; 32 } 33 }
原文:https://www.cnblogs.com/Auroras/p/10805873.html