CF2262F.Rank Removal
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Farmer John is playing a game involving an n×n binary matrix M. Throughout this problem, all matrix \href are computed over the field F2. Initially, the rank of M is guaranteed to be n.
On a move, let r be the rank of the current matrix M. Farmer John must choose exactly r distinct entries of M that are equal to 1 and change all of them to 0.
Farmer John wants to turn M into the zero matrix using the minimum possible number of moves.
For each test case, output the minimum number of moves and any sequence of moves that achieves it.
农夫约翰正在玩一个涉及 n×n 二进制矩阵 M 的游戏。在本题中,所有矩阵的 \href 均在域 F2 上计算。初始时,矩阵 M 的秩保证为 n。
在一次操作中,设当前矩阵 M 的秩为 r。农夫约翰必须恰好选择 M 中 r 个互不相同的值为 1 的元素,并将它们全部变为 0。
农夫约翰希望以最少的操作次数将 M 变为零矩阵。
对每个测试用例,输出最少操作次数,以及任意一个达到该次数的操作序列。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and m (2≤n≤300,n≤m≤n2) — the size of the matrix and the number of entries equal to 1.
Each of the next m lines contains two integers xi and yi (1≤xi,yi≤n), denoting that Mxi,yi=1.
All other entries of M are equal to 0.
It is guaranteed that all given cells are distinct.
It is guaranteed that the rank of M over F2 is n for every test case.
It is guaranteed that the sum of m over all test cases does not exceed 3002.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(2≤n≤300,n≤m≤n2),分别表示矩阵的大小以及值为 1 的元素个数。
接下来的 m 行中,每行包含两个整数 xi 和 yi(1≤xi,yi≤n),表示 Mxi,yi=1。
矩阵 M 中其余所有元素均为 0。
保证所有给定的单元格互不相同。
保证对于每个测试用例,矩阵 M 在 F2 上的秩均为 n。
保证所有测试用例的 m 值之和不超过 3002。
输出格式
For each test case, first output an integer k — the minimum number of moves needed to turn M into the zero matrix.
Then output k lines, each describing one move.
For each move, let r be the rank of the current matrix before the move. Output the integer r on a new line. Then, output r pairs of integers xi and yi representing the cells of a matrix we are changing to 0.
For every 1≤i≤r, the cell (xi,yi) must contain a 1 in the current matrix before the move. All chosen cells in the same move must be distinct.
If there are multiple optimal sequences of moves, you may output any of them.
对于每个测试用例,首先输出一个整数 k —— 将矩阵 M 变为零矩阵所需的最少移动次数。
然后输出 k 行,每行描述一次移动。
对于每次移动,设 r 为本次移动前当前矩阵的秩。在新的一行中输出整数 r;接着输出 r 对整数 xi 和 yi,表示本次移动中被置为 0 的矩阵单元格坐标。
对每个 1≤i≤r,单元格 (xi,yi) 在本次移动前的当前矩阵中必须为 1。同一次移动中所选的所有单元格必须互不相同。
若存在多个最优移动序列,可输出其中任意一个。
输入输出样例
输入#1
2 2 2 1 1 2 2 3 5 1 1 1 2 2 2 2 3 3 3
输出#1
1 2 1 1 2 2 2 3 1 2 2 3 3 3 2 1 1 2 2
说明/提示
For the first test case, the matrix is
\\left\[ \\begin{array}{cc} 1 & 0 \\\\ 0 & 1 \\end{array} \\right\].Its rank is 2, so we remove the two entries (1,1) and (2,2) in one move.
For the second test case, the initial matrix is
\\left\[ \\begin{array}{ccc} 1 & 1 & 0 \\\\ 0 & 1 & 1 \\\\ 0 & 0 & 1 \\end{array} \\right\].Its rank is 3. After removing (1,2), (2,3), and (3,3), the matrix becomes
\\left\[ \\begin{array}{ccc} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 0 \\end{array} \\right\],which has rank 2. We then remove (1,1) and (2,2) in the second move.
对于第一个测试用例,矩阵为
[1001].
其秩为 2,因此我们在一次操作中移除两个元素 (1,1) 和 (2,2)。
对于第二个测试用例,初始矩阵为
100110011.
其秩为 3。在移除 (1,2)、(2,3) 和 (3,3) 后,矩阵变为
100010000,
其秩为 2。随后我们在第二次操作中移除 (1,1) 和 (2,2)。
输入解题思路,AI测评打分。不知道怎么写?