QOJ.ac

QOJ

时间限制: 4 s 内存限制: 256 MB 总分: 100

#957. 分配问题

统计

公司有 $m$ 个空缺职位,有 $n \ge m$ 名候选人。显然,我们希望雇佣最优秀的候选人。我们不能雇佣同一名候选人担任两个或多个不同的职位,因此我们必须恰好雇佣 $m$ 名候选人。我们将为每个职位选择不同候选人的方式称为一种“分配”(assignment)。如果两个分配中存在某个职位雇佣的候选人不同,则这两个分配是不同的。

存在一个利润矩阵 $A$:$A_{ij} \ge 0$ 表示雇佣第 $j$ 名候选人担任第 $i$ 个职位所获得的利润。我们希望最大化所有雇佣带来的利润总和。如果一个分配使利润总和最大化,则称其为最优分配。

如果已知矩阵 $A$,选择最佳候选人将非常容易。不幸的是,人力资源部门的情况并非如此简单,他们无法提供矩阵 $A$。即使在面试了所有候选人之后,我们也只能比较两名候选人在同一职位上的表现。更准确地说,我们已知 $m$ 个长度为 $n$ 的排列 $P_i$。对于所有 $1 \le i \le m$,$1 \le x < y \le n$,满足 $A_{iP_{ix}} > A_{iP_{iy}}$。通俗地说,对于每个职位,我们都知道所有候选人的排名。

一名候选人被称为“有前途的”(promising),当且仅当存在一个与所有给定排名一致的矩阵 $A$,使得对于该矩阵,存在唯一的最优分配,且该候选人在该分配中被雇佣。

你需要找出所有有前途的候选人,以便我们对他们进行更深入的测试。

输入格式

第一行包含两个整数 $n$ 和 $m$ ($1 \le m \le 11$,$m \le n \le 1000$),分别表示候选人数和职位数。

接下来的 $m$ 行包含每个职位的排名。第 $i$ 行包含一个 $1$ 到 $n$ 的排列 $P_{i1}, P_{i2}, \dots, P_{in}$。

输出格式

第一行输出有前途的候选人数量,第二行按升序输出有前途的候选人的编号。

样例

样例输入 1

4 2
1 2 4 3
1 3 4 2

样例输出 1

3
1 2 3

样例输入 2

4 2
1 4 3 2
2 3 4 1

样例输出 2

2
1 2

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#317EditorialOpen题解jiangly2026-01-09 10:10:43View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.