Advertisement
at3107

B_final

Feb 6th, 2021
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. int32_t main()
  5. {
  6.     int t;
  7.     cin>>t;
  8.     int ans;
  9.     for(int i=0;i<t;i++)
  10.     {
  11.         int n;
  12.         cin>>n;
  13.         if(n<=2)
  14.         {
  15.             if(n==0) cout<<1<<endl;
  16.             else if(n==1) cout<<2<<endl;
  17.             else cout<<4<<endl;
  18.             continue;
  19.         }
  20.         int dp[n+1];
  21.         dp[0]=1,dp[1]=2,dp[2]=4;
  22.         for(int i=3;i<=n;i++) dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
  23.         if(i!=t-1) cout<<dp[n]<<endl;
  24.         ans=dp[n];
  25.     }
  26.     cout<<ans;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement