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的更多相关文章
随机推荐
- MySQL(十三)事务处理和字符集
一.事务处理 事务处理(transaction processing):是一种机制,用来维护数据库的完整性,管理必须成批执行的MySQL操作,以保证数据库不包含不完整的操作结果. 这样可以保证一组操作 ...
- Android TimeAnimator && TimeListener翻译
TimeAnimator:提供了一个简单的回调机制,通过 TimeAnimator.TimeListener,在动画的每一帧处通知你.这个动画器没有时间,插值或是对象值设定.回调监听器为每一帧动画接受 ...
- HiKey软硬件开发环境及其调试
HiKey是一款搭载华为海思麒麟620芯片,符合Linaro 96Boards标准的SBC开发板.它采用8核64位Cortex-A53处理器,主频高达1.2GHz. HiKey作为AOSP支持的一款产 ...
- VB6 变量定义作用域的一个奇特形式
C#或JAVA 下面的i定义是只会限定在if 条件块里的: if (1 == 2) { int i = 000; } else { i = 111;// 错误,未定义. } i = 222;//错误 ...
- Ionic2 App Import BrowserAnimationsModule or NoopAnimationsModule问题
在开发app的过程中遇见了动画相关方面的问题,具体如下: 解决方法是:在app.module.ts模块中引入BrowserAnimationsModule import { BrowserAnimat ...
- 算法相关——Java排序算法之桶排序(一)
(代码中对应一个数组的下标),将每个元素放入对应桶中,再将所有元素按顺序输出(代码中则按顺序将数组i下标输出arrary[i]次),即为{0,1,3,5,5,6,9}. 1.2 代码实现 /* *@ ...
- Ionic 中控件点击延迟的处理
原文发表于我的技术博客 本文分享了在 Ionic 中如何处理控件点击延迟的问题. 原文发表于我的技术博客 1. 问题描述 在 Ionic 中,当在 iOS 环境下运行元素的点击事件时,你会发现点击响应 ...
- linux下安装redis组件报错-gcc报错
报错如图: 1.解决办法 先安装gcc插件.删除redis解压后文件.重新解压
- openssl版本升级操作记录
需要部署nginx的https环境,之前是yum安装的openssl,版本比较低,如下: [root@nginx ~]# yum install -y pcre pcre-devel openssl ...
- 解决error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file
原文地址:http://blog.csdn.net/yjk13703623757/article/details/53217377 一.问题 运行hydra时,提示错误: hydra : error ...