#P2457. [SDOI2006] 仓库管理员的烦恼

    ID: 1463 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2006各省省选山东二分图费用流

[SDOI2006] 仓库管理员的烦恼

Description

Warehouse manager M has been very troubled lately because his boss gave him a difficult task: come up with a reasonable plan as soon as possible to reorganize the company’s warehouses.

There are nn warehouses and nn types of goods. Because the goods were not well categorized when purchased, most warehouses contain multiple types of goods, which causes a lot of trouble for the workers when moving goods.

Manager M’s task is to design a reasonable plan to reorganize the goods in the warehouses so that goods of the same type are stored in the same warehouse, making future management easier. During the reorganization, some goods will definitely need to be moved from one warehouse to another. The cost of each move equals the weight of the moved goods.

Programming task:

Please help manager M design a moving plan so that all goods are categorized properly: each type of goods occupies exactly one warehouse, or equivalently, each warehouse holds only one type of goods. At the same time, the total cost of moving the goods should be minimized.

Input Format

The first line contains nn (1n1501 \le n \le 150), the number of warehouses.

The following lines describe the goods in the warehouses. For the ii-th warehouse, line i+1i+1 contains the quantities xx of the nn types of goods (0x1000 \le x \le 100).

Output Format

Output the minimal total cost required to reorganize all the goods as required.

4
62 41 86 94 
73 58 11 12 
69 93 89 88 
81 40 69 13 

650

Hint

Sample explanation: The plan is as follows: type 11 goods go to warehouse 22; type 22 goods go to warehouse 33; type 33 goods go to warehouse 44; type 44 goods go to warehouse 11.

Translated by ChatGPT 5