Timus-1225.Flags

Problem NameFlags
JudgeTimus
Problem Linkhttps://acm.timus.ru/problem.aspx?space=1&num=1225
Algorithms & DSDynamic Programming
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll dp[50][5];
int main()
{
    fast;
    dp[1][1]=0;
    dp[1][1]=0;
    dp[1][2]=1;
    dp[1][3]=1;
    for(ll i=2; i<=46; i++)
    {
        dp[i][0]=dp[i-1][2];
        dp[i][1]=dp[i-1][3];
        dp[i][2]=dp[i-1][3]+dp[i-1][1];
        dp[i][3]=dp[i-1][2]+dp[i-1][0];
    }
    ll tcase=1;
    //cin>>tcase;
    for(ll test=1; test<=tcase; test++)
    {
        ll n;
        cin>>n;
        ll ans=dp[n][2]+dp[n][3];
        cout<<ans<<"\n";
    }
    return 0;
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
error: Alert: Content is protected !!