Skip to content

Instantly share code, notes, and snippets.

@IvanIsCoding
Created November 8, 2017 15:26
Show Gist options
  • Select an option

  • Save IvanIsCoding/a03f6216e8b6beeae577c79629009788 to your computer and use it in GitHub Desktop.

Select an option

Save IvanIsCoding/a03f6216e8b6beeae577c79629009788 to your computer and use it in GitHub Desktop.
Seletiva IOI 2015
// Ivan Carvalho
// Serrote - Seletiva IOI - OBI 2015
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e3 + 10;
const ll MOD = 1e9 + 7;
ll dp[MAXN][MAXN],n,k;
ll solve(ll tam,ll dentes){
if(tam == 3){
if(dentes == 0) return 4;
if(dentes == 1) return 2;
return 0;
}
if(dp[tam][dentes] != -1) return dp[tam][dentes];
return dp[tam][dentes] = (solve(tam-1,dentes-1)*(tam - 2*dentes) + solve(tam-1,dentes)*(2*dentes + 2)) % MOD;
}
int main(){
memset(dp,-1,sizeof(dp));
scanf("%lld %lld",&n,&k);
printf("%lld\n",solve(n,k));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment