Advertisement
at3107

Untitled

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