CF431B.Shower Line

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks.

There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.

Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2_i_ - 1)-th man in the line (for the current moment) talks with the (2_i_)-th one.

Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower.

We know that if students i and j talk, then the i-th student's happiness increases by g__ij and the j-th student's happiness increases by g__ji. Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.

许多学生住在宿舍里。宿舍是一个充满有趣娱乐和各种可能性的全新世界,但也有其缺点。

宿舍里只有一间淋浴间,而早晨却有许多学生希望使用它。因此,每天早上淋浴间门口都会排起一支由五人组成的队伍。淋浴间一开放,队伍中的第一个人便立即进入淋浴间。过一段时间后,第一个人离开淋浴间,下一个人随即进入。该过程持续进行,直至队伍中的所有人都完成淋浴。

淋浴需要花费一定时间,因此排队的学生在等待时会相互交谈。在任意时刻,排队的学生两两配对交谈:当前队伍中第 (2i−1)(2i-1) 个人与第 2i2i 个人交谈。

我们来更详细地观察这一过程。将五个人编号为 11 至 55。假设初始队列为 2315423154(即编号为 22 的学生站在队首)。那么,在淋浴间开放前,22 与 33 交谈,11 与 55 交谈,而 44 则无人交谈。接着,22 进入淋浴间。在 22 淋浴期间,33 与 11 交谈,55 与 44 也交谈。随后,33 进入淋浴间;在 33 淋浴期间,11 与 55 交谈,而 44 无人交谈。接着,11 进入淋浴间,在其淋浴期间,55 与 44 交谈。然后 55 进入淋浴间,最后 44 进入淋浴间。

已知若学生 ii 与学生 jj 交谈,则学生 ii 的幸福感增加 gijg_{ij},学生 jj 的幸福感增加 gjig_{ji}。你的任务是找出一个初始队列顺序,使得所有学生最终获得的总幸福感最大。请注意,某些学生对可能多次交谈。在上述示例中,学生 11 和 55 在淋浴间开放前等待时交谈了一次,又在 33 淋浴期间再次交谈。

输入格式

The input consists of five lines, each line contains five space-separated integers: the j-th number in the i-th line shows g__ij (0 ≤ g__ij ≤ 105). It is guaranteed that g__ii = 0 for all i.

Assume that the students are numbered from 1 to 5.

输入包含五行,每行包含五个用空格分隔的整数:第 ii 行中的第 jj 个数表示 gijg_{ij}(0≤gij≤1050 \leq g_{ij} \leq 10^5)。保证对所有 ii 均有 gii=0g_{ii} = 0。

假设学生编号为 11 到 55。

输出格式

Print a single integer — the maximum possible total happiness of the students.

输出一个整数——学生可能获得的总幸福感的最大值。

输入输出样例

  • 输入#1

    0 0 0 0 9
    0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0
    7 0 0 0 0

    输出#1

    32
  • 输入#2

    0 43 21 18 2
    3 0 21 11 65
    5 2 0 1 4
    54 62 12 0 99
    87 64 81 33 0

    输出#2

    620

说明/提示

In the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:

(_g_23 + _g_32 + _g_15 + _g_51) + (_g_13 + _g_31 + _g_54 + _g_45) + (_g_15 + _g_51) + (_g_54 + _g_45) = 32

.

在第一个样例中,队伍的最优排列为 23154。此时,总幸福值为:

(_g_23 + _g_32 + _g_15 + _g_51) + (_g_13 + _g_31 + _g_54 + _g_45) + (_g_15 + _g_51) + (_g_54 + _g_45) = 32

输入解题思路,AI测评打分。不知道怎么写?

首页