Shower Line

CodeForces - 431B

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 (2i - 1)-th man in the line (for the current moment) talks with the (2i)-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 gij and the j-th student's happiness increases by gji. 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.

Input

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

Assume that the students are numbered from 1 to 5.

Output

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

Examples

Input
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
Output
32
Input
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
Output
620

Note

In the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:(g23 + g32 + g15 + g51) + (g13 + g31 + g54 + g45) + (g15 + g51) + (g54 + g45) = 32

sol:5的全排列暴力枚举,本来以为要取最优解,没想到题目更简单。。。5!*5*5随便爆

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
int A[],C[][];
int main()
{
int i,j,ans=;
for(i=;i<=;i++)
{
for(j=;j<=;j++) R(C[i][j]);
}
for(i=;i<=;i++) A[i]=i;
do
{
int tmp=;
for(i=;i<=;i++) for(j=i;j<=;j+=) tmp+=C[A[j]][A[j+]]+C[A[j+]][A[j]];
ans=max(ans,tmp);
}
while(next_permutation(A+,A+));
Wl(ans);
return ;
}
/*
input
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
output
32 input
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
output
620
*/

codeforces431B的更多相关文章

随机推荐

  1. Kafka 笔记1

    Kafka 是对日志文件进行 append 操作,因此磁盘检索的开支是较小的:同时 为了减少磁盘写入的次数,broker 会将消息暂时 buffer 起来,当消息的个数(或大小)达到一定阀值时,再 f ...

  2. hibernate4使用原生jdbc进行批处理

    在hibernate中,有一级缓存session和二级缓存sessionFactory这些机制,一方面为编码提供了便利,同时也会有一些副作用.比如有较大的数据量交互的话,缓存反而会降低效率.最近在做一 ...

  3. keystone系列一:keystone基础

    一 什么是keystone keystone是OpenStack的身份服务,暂且可以理解为一个'与权限有关'的组件. 二 为何要有keystone Keystone项目的主要目的是为访问opensta ...

  4. Luogu4640 BJWC2008 王之财宝 容斥、Lucas

    传送门 题意:有$N$种物品,其中$T$个物品有限定数量$B_i$,其他则没有限定.问从中取出不超过$M$个物品的方案数,对质数$P$取模.$N,M \leq 10^9 , T \leq 15 , P ...

  5. React-使用styled-components

    1.安装 npm install --save styled-components 2.简单使用 style.js: import styled from 'styled-components'; i ...

  6. 【SQL】四种排序开窗函数

    一 .简单了解什么是开窗函数 什么是开窗函数,开窗函数有什么作用,特征是什么? 所谓开窗函数就是定义一个行为列,简单讲,就是在你查询的结果上,直接多出一列值(可以是聚合值或是排序号),特征就是带有ov ...

  7. 学习ML.NET(3): 导入数据集

    机器学习算法需要作用于数据,用来训练算法模型.数据集通常是以纯文本文件存储的表格数据,文件的每一行是一条数据记录,每条记录由多列组成,列之间用分隔符(一般是逗号,)分开,例如前面用到过的鸢尾花数据集. ...

  8. 开启mac上印象笔记的代码块

    Mac 印象笔记左上角菜单栏:偏好设置-->软件更新-->开启代码块 (Preferences -> Software Update -> Enable code block) ...

  9. Dell BOSS 卡是什么

    全名: Boot Optimized Storage Solution 针对 M.2 接口的 SSD,主板上必须设计接口进行适配. 设计一款主板对于硬件厂商来说是有成本的,其中包括 主板设计成本 产品 ...

  10. jackjson-databind-2.9.3 笔记

    问题 客户端请求: {"skip":0,"take":10,"corpName":"","cityCode&q ...