NC22398. Mysterious … Host
描述
输入描述
The only line contains two integers, the maximal order of the permutations and the divisor, separated by a space. It is guaranteed that P is prime.
输出描述
Output N lines; for, the n-th line contains one integer, the minimum number of permutations which Rikka needs to choose for order n, modulo P.
示例1
输入:
10 65537
输出:
1 1 3 12 52 240 1160 5795 29681 23951
C++11(clang++ 3.9) 解法, 执行用时: 727ms, 内存消耗: 628K, 提交时间: 2020-03-17 11:19:20
#include<iostream> #include<algorithm> using namespace std; int mod; void add(int &a,int b) { a+=b; if(a>=mod) a-=mod; } #define MAXNUM 5555 #define rep(i,s,t) for(int i=s;i<t;i++) int sum[MAXNUM][5],dp[MAXNUM]; int main() { int n; scanf("%d%d",&n,&mod); dp[1]=sum[1][1]=1; rep(i,2,n+1) { rep(j,1,i) rep(k,1,5) { add(sum[i][k],sum[i-j][k-1]*1LL*dp[j]%mod); if(k==4) add(sum[i][4],sum[i-j][4]*1LL*dp[j]%mod); } add(dp[i],sum[i][4]); rep(k,2,5) add(dp[i],sum[i][k]); sum[i][1]=dp[i]; } rep(i,1,n+1) printf("%d\n",dp[i]); }