Source Code
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define fast ios::sync_with_stdio(false);cin.tie(0);
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef tree<int, null_type, less<int>,
        rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int mod = 1e9 + 7;

ll dp[1001][1005];
int n;
int calc(int idx, int cnt){
	if(idx > n || cnt < 0) return 0;
	if(idx == n){
		if(cnt == 0)return 1;
		else return 0;
		}
	if(dp[idx][cnt] != -1) return dp[idx][cnt];
	ll &ret = dp[idx][cnt];
	ret = 0;
	
	ret = (ret + calc(idx+1, cnt-1))%mod;
	ret = (ret + calc(idx+1, cnt+1))%mod; 
	
	return ret;
	}

int main(){
	fast
	cin>>n;
	memset(dp,-1,sizeof(dp));
	
	
	
	ll ans = 0;
	for(int i=0;i<=n-5;i++){
		
		for(int j=i%2;j<=i;j+=2){
			ans = (ans + calc(i+5, j + 1))%mod;
			}
		}
	
	
	cout<<ans<<endl;
	
return 0;
}
Copy
Bracket Sequence Bahaa
GNU G++17
19 ms
8.9 MB
Wrong Answer