Untitled

 avatar
unknown
plain_text
2 years ago
1.9 kB
15
Indexable
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll mod=1000000007;
const double PI = 3.14159265358979323846;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fo(i ,n) for(ll i = 0 ; i < n ; i++)
#define mp make_pair
#define all(x) x.begin() , x.end()
#define ff first
#define ss second
#define pb push_back
#define vi vector<ll>
#ifndef ONLINE_JUDGE
  #include "debug.h"
#else
#define deb(...)
#endif


ll rec(ll index,ll n,ll k,ll pos1,ll pos2,ll comps){
	if(index > n){
		return k==comps;
	}
	if(comps > k){
		return 0;
	}
	ll ans=0;
	if(pos1 && pos2){
			ll op1 = rec(index+1,n,k,1,0,comps);
			ll op2 = rec(index+1,n,k,0,1,comps);
			ll op3 = rec(index+1,n,k,1,1,comps-1);
			ll op4 = rec(index+1,n,k,0,0,comps+1);
			ans += op1+op2+op3+op4;
		}else if(pos1 && !pos2){
			ll op1 = rec(index+1,n,k,1,0,comps);
			ll op2 = rec(index+1,n,k,0,1,comps+2);
			ll op3 = rec(index+1,n,k,1,1,comps);
			ll op4 = rec(index+1,n,k,0,0,comps);
			ans += op1+op2+op3+op4;
		}else if(!pos1 && pos2){
			ll op1 = rec(index+1,n,k,1,0,comps+2);
			ll op2 = rec(index+1,n,k,0,1,comps);
			ll op3 = rec(index+1,n,k,1,1,comps);
			ll op4 = rec(index+1,n,k,0,0,comps);
			ans += op1+op2+op3+op4;
		}else{
			ll op1 = rec(index+1,n,k,1,0,comps+1);
			ll op2 = rec(index+1,n,k,0,1,comps+1);
			ll op3 = rec(index+1,n,k,1,1,comps+1);
			ll op4 = rec(index+1,n,k,0,0,comps);
			ans += op1+op2+op3+op4;
		}
	
	return ans;
	
}

void solve() {
	ll n,k;
	cin >> n >> k;
	if(k==1){
		cout << 2 << endl;
		return;
	}
	ll prevpos1=0;
	ll prevpos2=0;
	ll ans = rec(2,n,k,0,0,1)+rec(2,n,k,1,0,2)+rec(2,n,k,0,1,2)+rec(2,n,k,1,1,1);
	cout << ans << endl;
}



 
int32_t main(){
    FAST;
    int t=1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Editor is loading...