B. Shower Line
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Sample test(s)
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

题目大意:输出最大的欢乐值。

思路:要输出最大的欢乐值,应该枚举全部的情况,找出最大的欢乐值,数据较小能够枚举。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#define LL int
#define inf 0x3f3f3f3f
using namespace std;
int a[6][6];
int f[]={0,1,2,3,4};
bool bj;
int main()
{
LL n,m,i,j,k,l;
LL a1,a2,a3,a4;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<4;i++)
{
for(j=i+1;j<5;j++)
{
a[i][j]=a[j][i]=a[i][j]+a[j][i];//枚举出全部可能的欢乐值
}
}
LL ans=0;
do//注意运行后推断
{
ans=max(ans,a[f[0]][f[1]]*2+a[f[1]][f[2]]*2+a[f[2]][f[3]]+a[f[3]][f[4]]);<span id="transmark"></span>
}
while(next_permutation(f,f+5))//注意排序问题。由于数组从0下标開始,若为1则不能够这么写
printf("%d\n",ans);
return 0;
}

Codeforces Round #247 (Div. 2) B的更多相关文章

  1. Codeforces Round #247 (Div. 2) ABC

    Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431  代码均已投放:https://github.com/illuz/Wa ...

  2. Codeforces Round #247 (Div. 2) B - Shower Line

    模拟即可 #include <iostream> #include <vector> #include <algorithm> using namespace st ...

  3. Codeforces Round #247 (Div. 2)

    A.水题. 遍历字符串对所给的对应数字求和即可. B.简单题. 对5个编号全排列,然后计算每种情况的高兴度,取最大值. C.dp. 设dp[n][is]表示对于k-trees边和等于n时,如果is== ...

  4. Codeforces Round #247 (Div. 2) C题

    赛后想了想,然后就过了.. 赛后....... 我真的很弱啊!想那么多干嘛? 明明知道这题的原型就是求求排列数,这不就是 (F[N]-B[N]+100000007)%100000007: F[N]是1 ...

  5. Codeforces Round #247 (Div. 2) C. k-Tree (dp)

    题目链接 自己的dp, 不是很好,这道dp题是 完全自己做出来的,完全没看题解,还是有点进步,虽然这个dp题比较简单. 题意:一个k叉树, 每一个对应权值1-k, 问最后相加权值为n, 且最大值至少为 ...

  6. [Codeforces Round #247 (Div. 2)] A. Black Square

    A. Black Square time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  7. Codeforces Round #247 (Div. 2) D. Random Task

    D. Random Task time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #247 (Div. 2) C D

    这题是一个背包问题 这样的 在一个k子树上 每个节点都有自己的k个孩子 然后 从原点走 走到 某个点的 和为 N 且每条的 长度不小于D 就暂停问这样的 路有多少条,  呵呵 想到了 这样做没有把他敲 ...

  9. 「专题训练」k-Tree(CodeForces Round #247 Div.2 C)

    题意与分析(Codeforces-431C) 题意是这样的:给出K-Tree--一个无限增长的树,它的每个结点都恰有\(K\)个孩子,每个节点到它\(K\)个孩子的\(K\)条边的权重各为\(1,2, ...

随机推荐

  1. 'NSUnknownKeyException' … setValue:forUndefinedKey:]: …not key value coding compliant

    解决一个问题: 当我添加一个IBout, 报了如下错误 NSUnknownKeyException' … setValue:forUndefinedKey:]: …not key value codi ...

  2. Farseer.net轻量级开源框架 中级篇:BasePage、BaseController、BaseHandler、BaseMasterPage、BaseControls基类使用

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: UrlRewriter 地址重写 下一篇:Farseer.net轻量级开源框架 中 ...

  3. PHP会话控制考察点

    为什么要使用会话控制技术 HTTP协议是无状态的,也就是说HTTP没有一个内建的机制来维护两个事务之间的状态.当一个用户完成一个请求发起第二个请求的时候,服务器无法知道这次请求是来自于上一次的客户.而 ...

  4. 查看外网IP

    同一个网络,登录不同网站/APP, 显示的登录IP可能不一样. 输入ip138.com 得到外网IP: 输入:http://www.net.cn/static/customercare/yourip. ...

  5. 引入msword

    找到解决方法了:不是直接引入mswork.tlh文件的,该文件是#import "C:\\Program Files\\Microsoft Office\\Office12\\MSWORD. ...

  6. 04XML CSS

    XML CSS 1. XML CSS <?xml-stylesheet  href ="样式表的URI"  type= "text/css" ?> ...

  7. Danfoss Motor - Automotive Motor: What Sensors Are There?

    The   Danfoss Motor     states that the motor sensor control system is the heart of the entire autom ...

  8. JavaSE-20 IO序列化

    学习要点 定义 IO如何序列化 序列化 序列化:是将对象的状态存储到特定存储介质中的过程. 反序列化:从特定存储介质中的数据重新构建对象的过程. 实现了java.io.Serializable接口的类 ...

  9. JavaSE-15 Log4j参数详解

    一:日志记录器输出级别,共有5级(从前往后的顺序排列) ①fatel:指出严重的错误事件将会导致应用程序的退出 ②error:指出虽然发生错误事件,但仍然不影响系统的继续运行 ③warn:表明会出现潜 ...

  10. JAVA基础——生产者消费者问题

    1.生产者消费者问题:经典案例 生产者和消费者问题是操作系统的经典问题,在实际工作中也常会用到,主要的难点在于协调生产者和消费者,因为生产者的个数和消费者的个数不确定,而生产者的生成速度与消费者的消费 ...