USACO: Cow Pedigrees dp

771 ワード

/*
ID: Jang Lawrence
PROG: nocows
LANG: C++
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long lng;
int  f(lng x)
{
    return (x%9901+9901)%9901;
}
int n,k;
lng dp[201][101];
int main()
{
  #ifndef  DEBUG
  freopen("nocows.in","r",stdin);
  freopen("nocows.out","w",stdout);
  #endif
  scanf("%d%d",&n,&k);
  for(int i=1;i<=k;++i) dp[1][i]=1;
  for(int i=3;i<=n;i+=2)
  for(int j=1;j<=k;++j)
  {
      for(int s=1;s<i-1;s+=2)
      dp[i][j]=f(dp[i][j]+dp[s][j-1]*dp[i-1-s][j-1]);
  }
  int u=f(dp[n][k]-dp[n][k-1]);
  printf("%d
",u); return 0; }