#abc199e. E - Permutation

    ID: 3959 传统题 1000ms 256MiB 尝试: 5 已通过: 1 难度: 10 上传者: 标签>来源atcoder动态规划状态压缩DPatcoder状压DPDP

E - Permutation

Score : 500500 points

问题陈述

打印满足以下条件的序列 aa 的数量,其中 aa(1,2,3,,N)(1, 2, 3, \dots, N) 的排列:

  • 对于每个整数 ii(满足 1iM1 \le i \le M),在 a1,a2,a3,,aXia_1, a_2, a_3, \dots, a_{X_i} 中至多有 ZiZ_i 个数小于等于 YiY_i

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

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

  • for every integer ii such that 1iM1 \le i \le M, at most ZiZ_i numbers among a1,a2,a3,,aXia_1, a_2, a_3, \dots, a_{X_i} are less than or equal to YiY_i .

Constraints

  • 2N182 \le N \le 18
  • 0M1000 \le M \le 100
  • 1Xi<N1 \le X_i \lt N
  • 1Yi<N1 \le Y_i \lt N
  • 0Zi<N0 \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.

Sample Input 1

3 1
2 2 1

Sample Output 1

4

The four sequences aa satisfying the condition are:

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

(1,2,3)(1, 2, 3) and (2,1,3)(2, 1, 3) violate the condition, since each of them has two numbers less than or equal to 22 among a1,a2a_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