bzoj4465: [Jsoi2013]游戏中的学问
DP 一个人要么加入一个圈,要么三个人开一圈
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; typedef long long LL; LL f[3100][3100]; int main() { LL n,k,mod; scanf("%lld%lld%lld",&n,&k,&mod); f[0][0]=1; for(LL i=3;i<=n;i++) for(LL j=1;3*j<=i&&j<=k;j++) { f[i][j]=(f[i-1][j]*(i-1))%mod; f[i][j]=(f[i][j]+(f[i-3][j-1]*(i-1)*(i-2))%mod)%mod; } printf("%lld\n",f[n][k]); return 0; }
pain and happy in the cruel world.