传统题 1000ms 256MiB

E - Permutation

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

E - Permutation

Score : $500$ points

Problem Statement

Print the number of sequences $a$ that are permutations of $(1, 2, 3, \dots, N)$ and satisfy the following condition:

  • for every integer $i$ such that $1 \le i \le M$, at most $Z_i$ numbers among $a_1, a_2, a_3, \dots, a_{X_i}$ are less than or equal to $Y_i$ .

Constraints

  • $2 \le N \le 18$
  • $0 \le M \le 100$
  • $1 \le X_i \lt N$
  • $1 \le Y_i \lt N$
  • $0 \le Z_i \lt N$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

X1X_1 Y1Y_1 Z1Z_1

X2X_2 Y2Y_2 Z2Z_2

X3X_3 Y3Y_3 Z3Z_3

\hspace{23pt} \vdots

XMX_M YMY_M ZMZ_M

Output

Print the answer.


3 1
2 2 1
4

The four sequences $a$ satisfying the condition are:

  • $(1, 3, 2)$
  • $(2, 3, 1)$
  • $(3, 1, 2)$
  • $(3, 2, 1)$

$(1, 2, 3)$ and $(2, 1, 3)$ violate the condition, since each of them has two numbers less than or equal to $2$ among $a_1, a_2$.


5 2
3 3 2
4 4 3
90

18 0
6402373705728000

2024寒假入门组刷题营(十二)

未参加
状态
已结束
规则
ACM/ICPC
题目
8
开始于
2024-2-12 13:30
结束于
2024-2-12 15:30
持续时间
2 小时
主持人
参赛人数
10