#P2196. [NOIP 1996 提高组] 挖地雷

    ID: 1153 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>动态规划,dp搜索2001NOIp 提高组深度优先搜索,DFS

[NOIP 1996 提高组] 挖地雷

Description

On a map there are NN (N20N \le 20) cellars, each containing a certain number of mines. The connections between cellars are given. After the data of the cellars and their connections are provided, a person can start digging mines from any cellar. Each time, they may move to a connected cellar whose index is strictly larger than the current node’s index to dig mines. The digging ends when there is no node that satisfies the condition. Design a digging plan so that the person can collect the maximum number of mines.

Input Format

Multiple lines.

The first line contains a single integer, the number of cellars NN.

The second line contains NN integers, representing the number of mines in each cellar.

Lines 33 to N+1N+1 describe the connections between cellars:

  • Line 33 has N1N-1 numbers (00 or 11), indicating whether there is a path from the first cellar to the 22-nd, 33-rd, …, NN-th cellar. For example, if line 33 is 1 1 0 0 001\ 1\ 0\ 0\ 0 \cdots 0, it means there is a path from cellar 11 to cellar 22, a path from cellar 11 to cellar 33, and no path from cellar 11 to cellar 44, cellar 55, …, cellar NN.
  • Line 44 has N2N-2 numbers, indicating whether there is a path from the second cellar to the 33-rd, 44-th, …, NN-th cellar.
  • Line N+1N+1 has 11 number, indicating whether there is a path from the (N1)(N-1)-th cellar to the NN-th cellar (where 00 means no path and 11 means there is a path).

Output Format

The first line prints the digging order when the maximum number of mines is collected. The indices of the cellars are separated by a single space, with no extra spaces.

The second line contains a single integer, the maximum number of mines that can be collected.

5
10 8 4 7 6
1 1 1 0
0 0 0
1 1
1

1 3 4 5
27

Hint

[Sample Explanation] The optimal path is 13451 \to 3 \to 4 \to 5, and the result is 2727.

[Source] NOIP 1996 Senior, Problem 3.

Translated by ChatGPT 5