当前位置:网站首页>Bzoj4465: [jsoi2013] learning in the game (DP)

Bzoj4465: [jsoi2013] learning in the game (DP)

2020-12-07 15:21:23 osc_ i5oyb1xr

Subject portal
.

solution :
f[i][j] Express i Personal share j The scheme of a circle .
So every one who comes in . He can't be in a circle . He got into other people's circles .
He can also form a circle of his own . Choose two people from the front and form a circle with him .


Code implementation :

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
typedef long long ll;
ll f[3100][1100],mod;
ll C(int x) {
  
  return x*(x-1)%mod;}
int main() {
    int n,K;scanf("%d%d%lld",&n,&K,&mod);
    f[0][0]=1;
    for(int i=1;i<=n;i++)for(int j=1;j<=min(K,i/3);j++) {
        f[i][j]=f[i-1][j]*(i-1)%mod;
        f[i][j]=(f[i][j]+f[i-3][j-1]*C(i-1))%mod;
    }printf("%lld\n",f[n][K]);
    return 0;
}

版权声明
本文为[osc_ i5oyb1xr]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201207150436893y.html