题目链接:http://codeforces.com/contest/431/problem/B

题目意思:给出5 * 5 的矩阵。从这个矩阵中选出合理的安排次序,使得happiness之和最大。当第i个人和第j个人talk 的时候,第i个人获得的happiness是g[i][j],第j 个人获得的happiness是g[j][i]。

好简单的一道题目,不知道昨晚徘徊好久都不敢打,五个for循环即可!数据量这么小......今天一次就过了...

谨以此来纪念自己的怯懦....

方法一:直接暴力枚举

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; #define LL long long
int g[][];
LL ans; int main()
{
for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
scanf("%d", &g[i][j]);
}
ans = ;
for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
{
if (i != j)
{
for (int k = ; k <= ; k++)
{
if (k != j && k != i)
{
for (int l = ; l <= ; l++)
{
if (l != k && l != i && l != j)
{
for (int p = ; p <= ; p++)
{
if (p != l && p != i && p != j && p != k)
{
// printf("i = %d, j = %d, k = %d, l = %d, p = %d\n", i, j, k, l, p);
LL sum = g[i][j] + g[j][i] + g[j][k] + g[k][j] + * (g[l][p] + g[p][l] + g[k][l] + g[l][k]);
ans = max(ans, sum);
}
}
}
}
}
}
}
}
}
printf("%lld\n", ans);
return ;
}

方法二:利用next_permutation (学人家代码写的)

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std; #define LL long long
const int maxn = ;
int grid[maxn+][maxn+];
int t[maxn];
LL ans, tmp; int main()
{
for (int i = ; i < maxn; i++)
{
for (int j = ; j < maxn; j++)
scanf("%d", &grid[i][j]);
}
for (int i = ; i < maxn; i++)
t[i] = i;
ans = ;
do
{
//0123: 01 talk 23 talk
tmp = grid[t[]][t[]] + grid[t[]][t[]];
tmp += grid[t[]][t[]] + grid[t[]][t[]];
//1234: 12 talk 34 talk
tmp += grid[t[]][t[]] + grid[t[]][t[]];
tmp += grid[t[]][t[]] + grid[t[]][t[]];
//23: 23 talk
tmp += grid[t[]][t[]] + grid[t[]][t[]];
//34: 34 talk
tmp += grid[t[]][t[]] + grid[t[]][t[]]; ans = max(ans, tmp);
}while (next_permutation(t, t+maxn));
printf("%lld\n", ans);
return ;
}

codeforces B. Shower Line 解题报告的更多相关文章

  1. codeforces A. Cinema Line 解题报告

    题目链接:http://codeforces.com/problemset/problem/349/A 题目意思:题目不难理解,从一开始什么钱都没有的情况下,要向每一个人售票,每张票价格是25卢布,这 ...

  2. Codeforces Round 665 赛后解题报告(暂A-D)

    Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...

  3. Codeforces Round 662 赛后解题报告(A-E2)

    Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...

  4. Codeforces Round #277.5 解题报告

    又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...

  5. codeforces A. Dima and Continuous Line 解题报告

    题目链接:http://codeforces.com/problemset/problem/358/A 题目意思:在横坐标上给出n个不同的点,需要把前一个点跟后一个点(这两个点的顺序是紧挨着的)用一个 ...

  6. codeforces B. Simple Molecules 解题报告

    题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...

  7. 【LeetCode】149. Max Points on a Line 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典+最大公约数 日期 题目地址:https://l ...

  8. codeforces 591A. Wizards' Duel 解题报告

    题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be ...

  9. codeforces 582A. GCD Table 解题报告

    题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...

随机推荐

  1. 洛谷P2625 豪华游轮

    题目描述 有一条豪华游轮(其实就是条小木船),这种船可以执行4种指令: right X : 其中X是一个1到719的整数,这个命令使得船顺时针转动X度. left X : 其中X是一个1到719的整数 ...

  2. ci框架——分页

    1:在models里面写一个模型:page_model.php class Page_model extends CI_Model{ function page($tablename,$per_num ...

  3. VirtualBox 5.0.10 中 Fedora 23 在安装了增强工具后无法自动调节虚拟机分辨率的问题(改)

    VirtualBox 5.0.10 中安装 Fedora 23,即使在安装了增强工具后,仍然会发现虚拟机无法根据 VirtualBox 的运行窗口大小自动进行分辨率调节.究其原因,主要是因为 Fedo ...

  4. win10+Linux18.04双系统安装

    给好多可爱的妹子重装了那么多次电脑,懒得码过程,因为我一般每次都要查一查...这次来个综合版吧,超简单,无脑操作. 首先说一下我的电脑Thinkpad + 500G 硬盘 (2014年买的老电脑) 首 ...

  5. T1046 旅行家的预算 codevs

    http://codevs.cn/problem/1046/ 题目描述 Description 一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时油箱是空的).给定两个城市之间的距离D ...

  6. python3.x对python2.x变动

    原文地址:http://rookiedong.iteye.com/blog/1185403 python 2.4 与 python 3.0 的比较 一. print 从语句变为函数 原:     pr ...

  7. Python3:urllib模块的使用

    Python3:urllib模块的使用1.基本方法 urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capath=N ...

  8. Nginx+Uwsgi+Django以及解决的一些问题

    1.pip3 install uwsgi,项目目录路径:/data/my_env1/monitor1/,项目名:monitor1,app名:show 测试启动: ln -s /data/linkdoo ...

  9. axis2调用WSDL接口

    public static JSONObject sendWsdl(String url,String xmlStr){ JSONObject res=new JSONObject(); try { ...

  10. MySQL安装总是失败,提示缺少Visual Studio 2013 Redistributable

    MySQL安装总是失败,提示缺少Visual Studio 2013 Redistributable,但是很疑惑,我明明已经安装了呀,原来问题出在版本上,以下提供了一个可以匹配新版本mysql的版本: ...