题目链接: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. Codevs 5564 陶陶摘苹果2

    5564 陶陶摘苹果2 时间限制: 1 s 空间限制: 16000 KB 题目等级 : 白银 Silver 题目描述 Description 陶陶已经够高摘到所有苹果了,但是他力量有限,最大承受质量为 ...

  2. 矩阵乘法 BZOJ 2738

    矩阵乘法 [问题描述] 给你一个N*N的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第K小数. [输入格式] 第一行两个数N,Q,表示矩阵大小和询问组数:接下来N行N列一共N*N个数,表示这个矩阵: ...

  3. Linux主机被SSH精神病(Psychos)暴力攻破后成为肉鸡的攻防过程

    近日公司局域网突然变得非常慢,上网受到很大影响,不仅仅是访问互联网慢,就连访问公司内部服务器都感到异常缓慢.于是对本局域网网关进行测试:   $ ping 10.10.26.254   发现延时很大, ...

  4. LOJ#3083.「GXOI / GZOI2019」与或和_单调栈_拆位

    #3083. 「GXOI / GZOI2019」与或和 题目大意 给定一个\(N\times N\)的矩阵,求所有子矩阵的\(AND(\&)\)之和.\(OR(|)\)之和. 数据范围 \(1 ...

  5. R12: How to add Microsoft Excel as Type to the Create Template List of Values in BI Publisher (Doc ID 1343225.1)

    Modified: 27-Oct-2013 Type: HOWTO In this Document Goal Solution References APPLIES TO: BI Publisher ...

  6. Linux网络驱动架构

    网络设备介绍 网络设备是计算机体系结构中必不可少的一部分,处理器如果想与外界通信,通常都会选择网络设备作为通信接口.众所周知,在 OSI(Open Systems Interconnection,开放 ...

  7. MBProgressHUD 显示方向异常

    一直在iphone上使用MBProgressHUD做提示信息视图.一直都没有什么问题,但用在ipad上使用时.却有时会出现显示方向不正常.如ipad屏幕是横的,但当MBProgressHUD出现时却依 ...

  8. [MDX] Build a Custom Provider Component for MDX Deck

    MDX Deck is a great library for building slides using Markdown and JSX. Creating a custom Providerco ...

  9. codeforces 553 A Kyoya and Colored Balls

    这个题.比赛的时候一直在往dp的方向想,可是总有一个组合数学的部分没办法求, 纯粹组合数学撸,也想不到办法-- 事实上,非常显然.. 从后往前推,把第k种颜色放在最后一个,剩下的k球.还有C(剩余的位 ...

  10. gulp配置 - PC

    初始化目录结构如下(图片看不清可以拖到桌面或者直接CTRL+鼠标滚轮进行观看) 开发环境示例: 上线环境示例: gulpfile.js(详解版) (2018-3-28)添加了scss处理(去除了les ...