Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull-Request [MyVault-12-15-2024] from Obsidian #47

Merged
merged 59 commits into from
Dec 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
43e9c87
PUSH NOTE : 模拟赛记录.md
hyj0824 Dec 15, 2024
6b06e86
PUSH ATTACHMENT : Drawing 2023-10-06 23.38.26.svg
hyj0824 Dec 15, 2024
f6aa8a3
PUSH NOTE : 板子.md
hyj0824 Dec 15, 2024
8dd12f2
PUSH NOTE : 逆序对.md
hyj0824 Dec 15, 2024
1064289
PUSH NOTE : 离散化.md
hyj0824 Dec 15, 2024
2844384
PUSH NOTE : 子集枚举.md
hyj0824 Dec 15, 2024
d727e17
PUSH NOTE : 哈希.md
hyj0824 Dec 15, 2024
d301977
PUSH NOTE : 二维数点与偏序问题.md
hyj0824 Dec 15, 2024
1e685fe
PUSH NOTE : 中位数相关.md
hyj0824 Dec 15, 2024
8bccba9
PUSH NOTE : tuple用法.md
hyj0824 Dec 15, 2024
0593ab9
PUSH NOTE : DFS卡时.md
hyj0824 Dec 15, 2024
865d33b
PUSH NOTE : 猫树.md
hyj0824 Dec 15, 2024
670559e
PUSH NOTE : 根号算法.md
hyj0824 Dec 15, 2024
3fe739f
PUSH NOTE : 树状数组.md
hyj0824 Dec 15, 2024
b653c89
PUSH NOTE : 并查集.md
hyj0824 Dec 15, 2024
21a2065
PUSH NOTE : index.md
hyj0824 Dec 15, 2024
93d5c70
PUSH NOTE : Hash with BSearch.md
hyj0824 Dec 15, 2024
86cdd63
PUSH NOTE : P3702 SDOI2017 序列计数.md
hyj0824 Dec 15, 2024
e2135e4
PUSH NOTE : P3176 数字串拆分.md
hyj0824 Dec 15, 2024
33bc3cf
PUSH NOTE : AGC031D A Sequence of Permutations.md
hyj0824 Dec 15, 2024
26bb5cf
PUSH NOTE : ABC293E Geometric Progression.md
hyj0824 Dec 15, 2024
db3a404
PUSH NOTE : 01排序问题.md
hyj0824 Dec 15, 2024
3497911
PUSH NOTE : index.md
hyj0824 Dec 15, 2024
3b76702
PUSH NOTE : 背包.md
hyj0824 Dec 15, 2024
4579c4e
PUSH NOTE : 树形dp.md
hyj0824 Dec 15, 2024
b1e7292
PUSH NOTE : 动态DP.md
hyj0824 Dec 15, 2024
058acca
PUSH NOTE : index.md
hyj0824 Dec 15, 2024
f88eca2
PUSH NOTE : yaml和json互转.md
hyj0824 Dec 15, 2024
3b83866
PUSH NOTE : Windows.md
hyj0824 Dec 15, 2024
fe47f06
PUSH ATTACHMENT : Pasted image 20241124173902.png
hyj0824 Dec 15, 2024
664afdb
PUSH ATTACHMENT : Pasted image 20241124174918.png
hyj0824 Dec 15, 2024
e3a26a2
PUSH NOTE : Linux.md
hyj0824 Dec 15, 2024
3749da8
PUSH NOTE : Git简介.md
hyj0824 Dec 15, 2024
57ee66d
PUSH NOTE : move语义.md
hyj0824 Dec 15, 2024
182c041
PUSH NOTE : 小草和柠檬绿.md
hyj0824 Dec 15, 2024
057df0d
PUSH ATTACHMENT : Pasted image 20240812033217.png
hyj0824 Dec 15, 2024
f15e6cc
PUSH ATTACHMENT : Pasted image 20240812033251.png
hyj0824 Dec 15, 2024
d8ea9b6
PUSH ATTACHMENT : Pasted image 20240812033308.png
hyj0824 Dec 15, 2024
0a6d93c
PUSH ATTACHMENT : Pasted image 20240812033319.png
hyj0824 Dec 15, 2024
decd7b4
PUSH ATTACHMENT : Pasted image 20240812033331.png
hyj0824 Dec 15, 2024
fc35dda
PUSH ATTACHMENT : Pasted image 20240812033353.png
hyj0824 Dec 15, 2024
29e6157
PUSH NOTE : 错排问题.md
hyj0824 Dec 15, 2024
a116f04
PUSH NOTE : 容斥原理和二项式反演.md
hyj0824 Dec 15, 2024
0fa0187
PUSH NOTE : Polya计数.md
hyj0824 Dec 15, 2024
29b91d5
PUSH NOTE : 高斯消元.md
hyj0824 Dec 15, 2024
fd9def9
PUSH NOTE : 速通矩阵.md
hyj0824 Dec 15, 2024
19ce6a9
PUSH NOTE : 行列式.md
hyj0824 Dec 15, 2024
b306278
PUSH NOTE : 线性基.md
hyj0824 Dec 15, 2024
299aff3
PUSH NOTE : 逆元.md
hyj0824 Dec 15, 2024
8420eb9
PUSH NOTE : 欧拉函数.md
hyj0824 Dec 15, 2024
e6764c3
PUSH NOTE : 从gcd到exgcd.md
hyj0824 Dec 15, 2024
2c19bdb
PUSH NOTE : 差分约束.md
hyj0824 Dec 15, 2024
a62e7f5
PUSH NOTE : LGV引理.md
hyj0824 Dec 15, 2024
93204f3
PUSH ATTACHMENT : Pasted image 20230629195206.png
hyj0824 Dec 15, 2024
fb00f8e
PUSH ATTACHMENT : Pasted image 20230629200443.png
hyj0824 Dec 15, 2024
3ae2a3b
PUSH ATTACHMENT : Pasted image 20230629192537.png
hyj0824 Dec 15, 2024
6fba360
PUSH NOTE : 2-SAT.md
hyj0824 Dec 15, 2024
bd9965e
PUSH NOTE : 切比雪夫距离与曼哈顿距离.md
hyj0824 Dec 15, 2024
fff4f4f
PUSH NOTE : README.md
hyj0824 Dec 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PUSH NOTE : P3702 SDOI2017 序列计数.md
hyj0824 committed Dec 15, 2024
commit 86cdd63f75c4be8768926717fe2b184704a01cf8
82 changes: 82 additions & 0 deletions docs/OI/做题记录/P3702 SDOI2017 序列计数.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
tags:
- 做题记录
- 矩阵乘法
- 组合数学
date: 2023-08-29
publish: true
---

> [!note] [P3702 [SDOI2017] 序列计数](https://www.luogu.com.cn/problem/P3702)
> Alice 想要得到一个长度为 $n$ 的序列,序列中的数都是不超过 $m$ 的正整数,而且这 $n$ 个数的和是 $p$ 的倍数。这 $n$ 个数中,至少有一个数是质数。有多少个序列满足她的要求?

用一个简单的容斥,所有和是 $p$ 倍数的序列**减去**和是 $p$ 倍数并且只选合数的序列,就是至少有一个数是质数的序列。

不妨用两个桶 $all[],npr[]$ 分别统计 $[1,m]$ 所有**数、合数**在 $\operatorname{mod} p$ 意义下的个数。

```cpp
notprime[1]=1;
for(int i=2; i<=m; i++) {
if(!notprime[i]) {
for(int j=i+i; j<=m; j+=i) notprime[j]=1;
}
}
for(int i=1; i<=m; i++) {
all[i%p]++;
if(notprime[i]) npr[i%p]++;
}
```

设 $f[i][j]$ 表示填完前 $i$ 个数,和为 $j$ ($\operatorname{mod} p$ 意义下)的序列总数(填所有数),$g[i][j]$ 填所有合数。

初值 $f[0][0]=g[0][0]=1$ ,结果 $f[n][0]-g[n][0]$ 。这里的第一维可以滚掉。

考虑枚举前一个数是 $k$ 来转移,则有 $O(n*q^2)$ 的朴素方法(保证下标非负):

$$
f'[j]=\sum^{p-1}_{k=0}f[(j-k+p)\%{p}]*w[k]
$$

其中 $w[]$ 为上面说的桶,$f,g$ 都可以这样处理,但是乘的桶不一样。

```cpp
f[0][0]=g[0][0]=1;
for(int i=1; i<=n; i++) {
for(int j=0; j<p; j++) {
for(int k=0; k<p; k++){
(f[i][j] += f[i-1][(j-k+p)%p]*all[k]) %=mod;
(g[i][j] += g[i-1][(j-k+p)%p]*npr[k]) %=mod;
}
}
}
```

将整个过程视为 $n$ 个阶段,则每次 $p^2$ 转移共涉及到 $p$ 个已知变量,若 $p=4$:

$$
\begin{bmatrix}
f_0 & f_1 & f_2 & f_3
\end{bmatrix}
\cdot
\begin{bmatrix}
w[0] & w[1] & w[2] & w[3] \\
w[3] & w[0] & w[1] & w[2] \\
w[2] & w[3] & w[0] & w[1] \\
w[1] & w[2] & w[3] & w[0]
\end{bmatrix}
=
\begin{bmatrix}
f'_0 & f'_1 & f'_2 & f'_3
\end{bmatrix}
$$

~~(大部分的矩阵都是挺有规律的,推的时候举个小例子归纳一下就行)~~ 不难看出下面的构造方法:

```cpp
for(int i=0;i<p;i++){
for(int j=0;j<p;j++){
F[i][j]=all[(j-i+p)%p]; // 确实可以这么构造
G[i][j]=npr[(j-i+p)%p];
}
}
```