题面

一个人要带\(n\)个物品,共有\(8\)种物品,每种的限制分别如下:

偶数个;0/1个;0/1/2个;奇数个;

4的倍数个;0/1/2/3个;0/1个;3的倍数个。

求方案数。

\(n<=10^{500}\)

题解

对于八个物品的限制,分别构造生成函数,然后乘起来就是我们要的解。

化简后得到$$F(x)=\frac{x}{(1-x)4}=x(1+x+x2+...)^4$$
现在考虑求第\(n\)项系数。考虑第\(n\)项的组合意义,即将\(n\)划分为\(4\)个自然数的方案数。
所以第\(n\)项为\(C_{n+2}^3\),时间复杂度\(O(1)\)

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
#define RG register
#define MOD 10007
#define INV 1668
inline int read()
{
    RG int x=0,t=1;RG char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=-1,ch=getchar();
    while(ch<='9'&&ch>='0')x=(x*10+ch-48)%MOD,ch=getchar();
    return x*t;
}
int main()
{
	int n=read();
	printf("%lld\n",1ll*n*(n+1)%MOD*(n+2)%MOD*INV%MOD);
	return 0;
}

相关文章:

  • 2021-12-19
  • 2022-01-10
  • 2021-09-15
  • 2021-07-23
  • 2021-06-06
  • 2021-07-28
  • 2021-05-19
  • 2021-11-17
猜你喜欢
  • 2021-06-29
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2022-02-27
  • 2021-06-23
相关资源
相似解决方案