codeforces431B
Shower Line
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
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
32
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
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的更多相关文章
随机推荐
- B-Tree外存数据结构 _(B 树)第二部分
2. B 树 B 树是为了磁盘或其它存储设备而设计的一种多叉(相对于二叉,B树每个内结点有多个分支,即多叉)平衡查找树 一棵B树,一棵关键字为英语中辅音字母的B树,现在要从树中查找字母R(包含n[x] ...
- 【Codeforces Round 1114】Codeforces #538 (Div. 2)
Codeforces Round 1114 这场比赛做了\(A\).\(C\).\(D\).\(E\),排名\(134\). \(B\)题做了很长时间,好不容易最后一分钟\(Pretest\ Pass ...
- SkylineGlobe 如何实现FlyTo定位到目标点之后触发的事件函数
之前有朋友问,如何在Skyline里面实现FlyTo定位到目标点之后触发的事件函数呢? 下面的这段代码,就可以帮你解决这个问题. <!DOCTYPE html PUBLIC "-//W ...
- [03] mapper.xml的基本元素概述
1.select 我们基于这个持久层接口 GirlDao: public interface GirlDao { List<Girl> findByAge(int age); Girl f ...
- LOJ6089 小Y的背包计数问题 背包、根号分治
题目传送门 题意:给出$N$表示背包容量,且会给出$N$种物品,第$i$个物品大小为$i$,数量也为$i$,求装满这个背包的方案数,对$23333333$取模.$N \leq 10^5$ $23333 ...
- WPF 带清除按钮的文字框SearchTextBox
原文:WPF 带清除按钮的文字框SearchTextBox 基于TextBox的带清除按钮的搜索框 样式部分: <!--带清除按钮文字框--> <Style TargetType=& ...
- 解决项目无法添加VBIDE问题
为了方便大家引用,我直接把写好的文件放上来,方便大家下载.要注意的是:解压后需要把文件 VBIDE.DLL放入系统的(如果你的系统是32位,那就是 C:\windows\system32\..) 目录 ...
- Gitlab备份和恢复操作记录
前面已经介绍了Gitlab环境部署记录,这里简单说下Gitlab的备份和恢复操作记录: 1)Gitlab的备份目录路径设置 [root@code-server ~]# vim /etc/gitlab/ ...
- Oracle数据库重做日志及归档日志的工作原理说明
Oracle数据库重做日志及归档日志的工作原理: lgwr进程将redo log buffer中的重做数据写入到redo log中,此时的redo log分组,每当一个redo log group写满 ...
- svg矢量图在flex布局中样式扭曲的问题
问题机型 小米5 华为nova 其他未知的可能机型 问题描述 利用flex 布局的一行中, 左一样式: -webkit-box-flex: 0; flex: 0 1 auto; 左二样式: -webk ...