Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .

0 like 0 dislike
3,113 views

in Online Assessments by Expert (144,420 points)

2 Answers

0 like 0 dislike
 #include <bits/stdc++.h>

using namespace std;
typedef long long int ll ; 
ll dp[500][5] ; 
ll n ; 

int main() {
    
    cin>>n ; 
    
    
    //2......right..
    //3.....left...
    //1.................full
    
    dp[1][1] = 0 ; 
    dp[1][2] = 0 ; 
    dp[1][3] = 0 ; 
    dp[2][1] = 3 ; 
    dp[2][2] = 1 ; 
    dp[2][3] = 1 ; 
    
  
    
    
    ll i = 3 ; 
    while(i<=n){
        
        dp[i][1] = 3*dp[i-2][1] + dp[i-2][2] + dp[i-2][3] ; 
        dp[i][2] = dp[i-2][1] + dp[i-2][2] ; 
        dp[i][3] = dp[i-2][1] + dp[i-2][3] ; 
        
        i++;
    }
    
    cout<<dp[n][1] ; 
    return 0 ; 
}
by Expert (144,420 points)
0 like 0 dislike

Image of Question : 

by Expert (144,420 points)
...