#P13007. 【MX-X13-T2】「KDOI-12」不要去思考未来,把这留给未来的你。

    ID: 11695 远端评测题 2000ms 512MiB 尝试: 1 已通过: 1 难度: 5 上传者: 标签>图论O2优化枚举位运算梦熊比赛

【MX-X13-T2】「KDOI-12」不要去思考未来,把这留给未来的你。

Description

The mock contest consists of TT problems. Each problem has nn subtasks and mm special properties. Each subtask satisfies a subset of the mm special properties.

A subtask dependency (i,j)(i,j) means that subtask jj depends on subtask ii—that is, subtask jj can only be passed after subtask ii is passed.

Considering that the problem setters are lazy and the online judge is "not very smart," the number of subtask dependencies should be minimized. Now, you need to determine the minimum number of subtask dependencies required to ensure:

  1. There does not exist a pair of subtasks (x,y)(x, y) such that:

    • All test cases satisfying subtask yy must also satisfy subtask xx, but
    • It is still possible to pass subtask yy without passing subtask xx.
  2. There does not exist a pair of subtasks (x,y)(x, y) such that:

    • There exists a test case satisfying subtask yy but not satisfying subtask xx, but
    • It is impossible to pass subtask yy without passing subtask xx.

Formally, let SiS_i denote the set of special properties satisfied by subtask ii. You need to select the smallest possible number of (ux,vx)(u_x, v_x) pairs such that:

  • For any (i,j)(i,j) where SiSjS_i \subseteq S_j, there exists a sequence j=p1,p2,,pm=ij = p_1, p_2, \dots, p_m = i such that for all 1k<m1 \leq k < m, there exists xx where (ux,vx)=(pk,pk+1)(u_x, v_x) = (p_k, p_{k+1}).
  • For any (i,j)(i,j) where Si⊈SjS_i \not\subseteq S_j, there does not exist any sequence j=p1,p2,,pm=ij = p_1, p_2, \dots, p_m = i such that for all 1k<m1 \leq k < m, there exists xx where (ux,vx)=(pk,pk+1)(u_x, v_x) = (p_k, p_{k+1}).

Your task is to find the minimum number of such pairs.

Input Format

  • The first line contains a positive integer TT, the number of problems.
  • For each problem:
    • The first line contains two positive integers nn and mm, the number of subtasks and special properties, respectively.
    • The next nn lines each contain a binary string of length mm. The jj-th character of the ii-th string is 1 if and only if the ii-th subtask satisfies the jj-th special property.
    • It is guaranteed that no two subtasks satisfy the exact same set of special properties.

Output Format

For each problem, output a single non-negative integer—the minimum number of subtask dependencies required.

3
4 2
00
01
10
11
5 4
1110
1100
1000
0001
0000
7 4
0101
1101
1001
0010
1110
0100
1000
4
4
7

Hint

Sample Explanation

For the second problem: Suppose the four special properties are ABCD\text{ABCD}. Then, the five subtasks correspond to the following sets:

  • {A,B,C}\{\text{A}, \text{B}, \text{C}\}
  • {A,B}\{\text{A}, \text{B}\}
  • {A}\{\text{A}\}
  • {D}\{\text{D}\}
  • \varnothing (empty set)

The following dependency configuration is optimal:

  • (1,2)(1, 2)
  • (2,3)(2, 3)
  • (3,5)(3, 5)
  • (4,5)(4, 5)

Data Range

Test Case n,mn, m \leq Special Property
121\sim2 22 None
393\sim9 55
101310\sim13 1010
142014\sim20 1616 A
212521\sim25 None
  • Special Property A: Each subtask satisfies at most two special properties.

For all test cases:

  • 1T61 \leq T \leq 6,
  • 1n,m161 \leq n, m \leq 16,
  • Input strings consist of 0 and 1,
  • No two subtasks share the exact same set of special properties.

Translated by DeepSeek V3.