【自出题2:五题】2020-11-27 组合数学


作者: 溢流眼泪

A : Rooks

Description:

A Rook is a kind of chess. It can attack/move to the same row, or the same column, but not other areas.

You place n Rooks in a n × n n\times n n×n board. How many ways to place them s.t. every rook can’t attack other rooks for now?

It’s too easy, so Nick has another question for you.

Each rook has a color, identified by an id. In another word, we say two chess are same if an only if they have the same color.

Two ways are different iff one rook is placed at different area or one place has different color rook.

So many ways, please modulo 1e9+7

Input

N representing number of rooks as well as the size of the board

next n lines, each contains a color id c i c_i ci

Range

N ≤ 2 e 5 N\le 2e5 N2e5

c i ≤ 2 e 5 c_i\le 2e5 ci2e5

Sample In

2

1

2

Sample Out

4

Explain

#1 #2 1# 2#

2# 1# #2 #1

B : Endless counting

give you an inequality. How many different solutions it has?

{ x 1 + x 2 + ⋯ + x n = r x 1 ≥ c 1 ⋮ x n ≥ c n \begin{cases}x_1+x_2+\cdots+x_n=r\\x_1\ge c_1\\\vdots\\x_n\ge c_n\end{cases} x1+x2++xn=rx1c1xncn

luckily, every number is integer! (???)

and answer may be large , please modulo p p p ,which is a prime

Input

N r p

c 1 ⋯ c n c_1\cdots c_n c1cn

Range

n ≤ 2 e 5 n\le 2e5 n2e5

p ≤ 1 e 6 p\le 1e6 p1e6

∣ c i ∣ ≤ 1 e 9 |c_i|\le 1e9 ci1e9

Sample In

2 2 10013

-1

0

Sample Out

4

Explain

x 1 = x_1= x1= -1 0 1 2

x 2 = x_2= x2= 3 2 1 0

C : Overlapping circles

Description

there are n different overlapping circles.

magically , each two circles are have two intersection points, and no point passes three circles.

how many different areas divided by these circles?

remember to modulo 1e9+7

Range

C a s e s ≤ 100 Cases\le 100 Cases100

n ≤ 1 e 18 n\le 1e18 n1e18

Sample in

1

2

3

4

Sample out

2

4

8

14

D : Strange counting

Description

a matrix of ∞ × ∞ \infin\times\infin ×

at first you are at (1,1),the left top of the matrix

you could go down one unit, or go right-down (each for one unit)

and you can’t pass the diagonal (but can reach to).how many ways for you to get to the (n,m)?

please modulo 51257 because it is beautiful.

Range0

m ≤ n ≤ 1 e 18 m\le n\le 1e18 mn1e18

Sample in

n m

3 2

Sample out

2

E : Kings

Description:

A King is a kind of chess. It can attack/move to it’s one unit surrounding’s place ,i.e.

(O is the king, X is the place he can attack to)
# # # # # # X X X # # X O X # # X X X # # # # # # \#\#\#\#\#\\ \#XXX\#\\ \#XOX\#\\ \#XXX\#\\ \#\#\#\#\#\\ ######XXX##XOX##XXX######

You place k Kings in a n × n n\times n n×n board. How many ways to place them s.t. every king can’t attack other kings for now?

Input

N K

Range

N ≤ 9 N\le 9 N9

k ≤ N 2 k \le N^2 kN2

Sample In

3 2

Sample Out

16

自出题答案-2020/11/27 专题:组合数学

A:

难度:绿题

方法数为 n ! n ! n 1 ! n 2 ! ⋯ n k ! \frac{n!n!}{n_1!n_2!\cdots n_k!} n1!n2!nk!n!n!

n i n_i ni 表示每种颜色的个数。

证明:不考虑颜色,易得方案数为 n ! n! n!

然后套一个多重集排列公式即可。

预处理阶乘和逆元直接输出即可。

B:

难度:蓝题

首先需要用到扩展卢卡斯定理:卢卡斯定理模板题

就是在 O ( p ) O(p) O(p) 算出 C i j % p C_i^j\%p Cij%p 的东西

接下来,需要知道 无限多重集的组合数

S为有k种类型对象的无限多重集合,它的r组合的个数= ( r + k − 1 r ) \begin{pmatrix}r+k-1\\r\end{pmatrix} (r+k1r)

换句话就是说求 { x 1 + x 2 + ⋯ + x n = r x 1 ≥ 0 ⋮ x n ≥ 0 \begin{cases}x_1+x_2+\cdots+x_n=r\\x_1\ge 0\\\vdots\\x_n\ge 0\end{cases} x1+x2++xn=rx10xn0 的方案数就是 ( r + n − 1 r ) \begin{pmatrix}r+n-1\\r\end{pmatrix} (r+n1r)

但是现在每个 x i ≥ c i x_i\ge c_i xici,我们只需要设 y i = x i − c i ≥ 0 y_i=x_i-c_i\ge0 yi=xici0 然后带入式子中:

{ y 1 + y 2 + ⋯ + y n + c 1 + ⋯ + c n = r y 1 ≥ 0 ⋮ y n ≥ 0 \begin{cases}y_1+y_2+\cdots+y_n+c_1+\cdots+c_n=r\\y_1\ge 0\\\vdots\\y_n\ge 0\end{cases} y1+y2++yn+c1++cn=ry10yn0

答案即为 ( r − ∑ c + n − 1 r − ∑ c ) \begin{pmatrix}r-\sum c+n-1\\r-\sum c\end{pmatrix} (rc+n1rc)

注意: ∑ c \sum c c 可能很大, 要用Long Long 存,用ex-Lucas 计算。

C:

难度:黄题

递推式子 f n = f n − 1 + 2 ( n − 1 ) f_n=f_{n-1}+2(n-1) fn=fn1+2(n1)

答案为 n 2 − n + 2 n^2-n+2 n2n+2

D:

难度:黄题

递推式子 f n , m = f n − 1 , m − 1 + f n − 1 , m f_{n,m}=f_{n-1,m-1}+f_{n-1,m} fn,m=fn1,m1+fn1,m

易得为组合数。答案即为 C n m % p C_n^m\%p Cnm%p

E:

难度:蓝题

SCOI2005互不侵犯

状压DP:

d p [ i ] [ j ] [ k ] dp[i][j][k] dp[i][j][k]:

当前为第 i i i 行,摆放棋子状态为 j j j ,总共用了 k k k 个棋子的方案数。

状态转移: d p [ i ] [ j ] [ k ] = ∑ d p [ i − 1 ] [ p ] [ k − c n t j ] dp[i][j][k]=\sum dp[i-1][p][k-cnt_j] dp[i][j][k]=dp[i1][p][kcntj]

合法性判断:

当前行合法: j & ( 1 < < j ) = 0 j\&(1<<j)=0 j&(1<<j)=0

转移合法 : j & p = 0 j & ( p < < 1 ) = 0 ( j < < 1 ) & p = 0 j\&p=0\\j\&(p<<1)=0\\(j<<1)\&p=0 j&p=0j&(p<<1)=0(j<<1)&p=0

猜你喜欢

转载自blog.csdn.net/weixin_45775438/article/details/110672143