题目链接: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. form表单提交file

    form表单提交文件,这毫无疑问不是个好办法.但是,存在既有意义.既然H5都还让着东西存在着,呢么必然有其意义. form表单中的input type=file这个空间,不得不说奇丑无比!问题是还不能 ...

  2. linux 内核源码arch/ 目录的前世今生

    历史的痕迹:在最新的linux-2.6.31/arch/arm/文件夹下,仍然保留Linux最初向ARM处理器移植的痕迹,最初的移植由黑客完成,在老的移植的代码文件的头部保留着黑客的名字:最初的ARM ...

  3. spl_autoload_register() && __autoload函数

    一.__autoload 这是一个自动加载函数,在PHP5中,当我们实例化一个未定义的类时,就会触发此函数. 在index.php中,由于没有包含test.class.php,在实例化printit时 ...

  4. 前端MVC Vue2学习总结(九)——Vuex状态管理插件

    一.概要 1.1.Vuex定义与注意事项 Vuex是为vue.js框架更好的管理状态而设计一个插件.Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的 ...

  5. 异常来自 HRESULT:0x800A01A8

    Windows 10 Enterprise Microsoft Office 2013 – Excel Oracle BI Publisher Desktop 11.1.1.7 异常来自 HRESUL ...

  6. Vue.js 和 MVVM

    MVVM 是Model-View-ViewModel 的缩写,它是一种基于前端开发的架构模式,其核心是提供对View 和 ViewModel 的双向数据绑定,这使得ViewModel 的状态改变可以自 ...

  7. 数据库的DDL、DML和DCL的区别与理解

    DML(data manipulation language): 它们是SELECT.UPDATE.INSERT.DELETE,就象它的名字一样,这4条命令是用来对数据库里的数据进行操作的语言 DDL ...

  8. 【Todo】【转载】Scala中Array, List, Tuple的区别

    参考了这篇文章: https://my.oschina.net/u/1034176/blog/512314 1. 在Scala 2.7中,Array.List都不能混合类型,只有Tuple可以:而在S ...

  9. MFC 小知识总结三

    1 载入资源位图 1 获取程序实例 HINSTANCE   m_hInst; m_hInst=AfxGetInstanceHandle();                         //获取程 ...

  10. 从实例看hibernate的主键生成策略

    学习了hibernate会发现.hibernate中有实体类.实体类的映射文件.可是我们怎么样才干知道实体类的主键是如何的生成方式呢?hibernate提供的主键生成策略帮我们完美地解答了这个疑问.以 ...