QOJ.ac

QOJ

Time Limit: 4 s Memory Limit: 256 MB Total points: 100

#957. 指派問題

Statistics

公司有 $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}}$。換句話說,對於每個職位,我們都知道所有候選人的排名。

若且唯若存在一個與所有給定排名一致的矩陣 $A$,使得對於該矩陣而言,存在唯一一個最佳指派,且該特定候選人被聘用,則稱該候選人為「有前途的」(promising)。

你需要找出所有有前途的候選人,以便我們能對他們進行更深入的測試。

輸入格式

第一行包含兩個整數 $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.