题目链接: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. 云计算与 OpenStack

    “云计算” 算是近年来最热的词了.现在 IT 行业见面不说这三个字您都不好意思跟人家打招呼. 对于云计算,学术界有各种定义,大家有兴趣可以百度一下. CloudMan 这里主要想从技术的角度谈谈对云计 ...

  2. HTML 文档之 Head 最佳实践--摘抄

    HTML 文档之 Head 最佳实践 story 01-10 阅读 353 收藏 0 收藏 这篇文章整理了作者认可的一些最佳实践,写在这里与各位分享 阅读原文折叠收起 HTML 文档之 Head 最佳 ...

  3. Codeforces 271D - Good Substrings [字典树]

    传送门 D. Good Substrings time limit per test 2 seconds memory limit per test 512 megabytes input stand ...

  4. 标准C程序设计七---11

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...

  5. set_include_path() &&get_include_path()用法

    function initialize(){    set_include_path(get_include_path().PATH_SEPARATOR . "core/");   ...

  6. ftrace用法

    ftrace官方文档在kernel/Documentation/trace/ftrace.txt文件中. 使用ftrace接口之前,如果系统没有自动挂载debugfs文件系统,则要先手动挂载. # m ...

  7. max file descriptors [4096] for elasticsearch proess is too low, increase to at least [65536]

    修改文件 /etc/security/limits.conf 加入以下两行: sonar hard nofile 65536 sonar soft nofile  65536 #备注:sonar这里是 ...

  8. Delphi+MySQL:TADOQuery使用插入中文乱码解决方法

    Delphi+MySQL:TADOQuery使用插入中文乱码解决方法 with adoquery dobeginclose;sql.clear;sql.text:=' insert into test ...

  9. commons.apache

    1.ToStringBuilder //对象及其属性一行显示 System.out.println(ToStringBuilder.reflectionToString(u)); System.out ...

  10. bzoj 4457: 游戏任务

    4457: 游戏任务 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 128  Solved: 71[Submit][Status][Discuss] D ...