101994: [AtCoder]ABC199 E - Permutation

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

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:

$N$ $M$
$X_1$ $Y_1$ $Z_1$
$X_2$ $Y_2$ $Z_2$
$X_3$ $Y_3$ $Z_3$
$\hspace{23pt} \vdots$
$X_M$ $Y_M$ $Z_M$

Output

Print the answer.


Sample Input 1

3 1
2 2 1

Sample Output 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$.


Sample Input 2

5 2
3 3 2
4 4 3

Sample Output 2

90

Sample Input 3

18 0

Sample Output 3

6402373705728000

Input

题意翻译

第一行给定 $n$ 和 $m$。后 $m$ 行,每行给定一个规则。 - 规则:后 $m$ 行每行给出三个整数 $X_i,Y_i,Z_i$,表示在排列的前 $X_i$ 个数字中最多只能有 $Z_i$ 个数字小于等于 $Y_i$。 构造长度为 $n$ 的排列,求最多可以构造多少个满足所有规则的排列。

加入题单

算法标签: