题意:给出五个人的编号,分别为 1 2 3 4 5,他们在排队,

最开始的时候,1和2可以交谈,3和4可以交谈 然后1走了之后,2和3交谈,4和5可以交谈 2走了之后,3和4可以交谈, 3走了之后,4和5可以交谈

给出一个5*5的矩阵,问最大的交谈的值, 比如2和3交谈,交谈的值为g[2][3]+g[3][2]

直接枚举排列,因为5!=120,算出每一种排列的交谈值,找出最大值

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int g[][]; int main(){
int n,a[]={,,,,};
n=;
int p[]; for(int i=;i<=;i++)
for(int j=;j<=;j++) cin>>g[i][j]; int ans=;
int maxx=-;
do{
for(int i=;i<;i++) {
// printf("%d ",a[i]);
p[i]=a[i];
} // printf("\n");
int a=g[p[]][p[]]+g[p[]][p[]]+g[p[]][p[]]+g[p[]][p[]];
int b=g[p[]][p[]]+g[p[]][p[]]+g[p[]][p[]]+g[p[]][p[]];
int c=g[p[]][p[]]+g[p[]][p[]];
int d=g[p[]][p[]]+g[p[]][p[]];
ans=a+b+c+d;
maxx=max(ans,maxx);
// printf("maxx=%d\n",maxx);
// printf("ans=%d\n",ans); } while(next_permutation(a,a+)); printf("%d\n",maxx);
return ;
}

codeforces 431 B Shower Line【暴力】的更多相关文章

  1. [codeforces 549]G. Happy Line

    [codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love ...

  2. codeforces B. Shower Line 解题报告

    题目链接:http://codeforces.com/contest/431/problem/B 题目意思:给出5 * 5 的矩阵.从这个矩阵中选出合理的安排次序,使得happiness之和最大.当第 ...

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

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

  4. Codeforces Gym 100015H Hidden Code 暴力

    Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...

  5. Codeforces gym 100685 A. Ariel 暴力

    A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...

  6. Codeforces Gym 100637G G. #TheDress 暴力

    G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...

  7. Codeforces 626D Jerry's Protest(暴力枚举+概率)

    D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  8. codeforces 650D D. Image Preview (暴力+二分+dp)

    题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memo ...

  9. Codeforces 839D Winter is here - 暴力 - 容斥原理

    Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n s ...

随机推荐

  1. Http Url Get请求方式需要对中文参数进行编码

    public static void main(String[] args) { try { String mytext = java.net.URLEncoder.encode("上海南站 ...

  2. Javascript全局变量的使用方法

    1.demo例子说明 <script type="text/javascript"> var gDivId; //js全局变量 function geocoder(la ...

  3. Too many levels of symbolic links 问题

    Too many levels of symbolic links 问题 Posted on 2011-11-30 20:33 张贺 阅读(5826) 评论(0) 编辑 收藏 今天弄了个ZendStu ...

  4. PHP event 事件机制

    PHP event 事件机制   <?php /* * PHP 事件机制 */ class baseClass{ private $_e; public function __set($name ...

  5. delphi的socket通讯 多个客户端 (转)

    ClientSocket组件为客户端组件.它是通信的请求方,也就是说,它是主动地与服务器端建立连接. ServerSocket组件为服务器端组件.它是通信的响应方,也就是说,它的动作是监听以及被动接受 ...

  6. POJ 1988

    #include<iostream> #include<stdio.h> #include<algorithm> #define MAXN 30005 using ...

  7. linux下tomcat下部署项目如何打包压缩备份

    范例一:将整个 /etc 目录下的文件全部打包成为 /tmp/etc.tar[root@linux ~]# tar -cvf /tmp/etc.tar /etc <==仅打包,不压缩![root ...

  8. ios开发--企业帐号发布

    这两天需要发布一个ipa放到网上供其他人安装,需要用到企业级开发者账号. 首先详细说明一下我们的目标,我们需要发布一个ipa放到网上,所有人(包括越狱及非越狱设备)可以直接通过链接下载安装,不需要通过 ...

  9. Fatal error: cannot allocate memory for the buffer pool

    mysql有时候会被系统kill掉,原因是内存不够了,一般都是Ubuntu出现的,因为Ubuntu吃内存,你们又给的不多.. 咋解决呢? 重启服务器是可以的,起码暂时可以了, 可以考虑加内存,或者增加 ...

  10. 浅析c语言中的变量(局部变量,外部变量,静态变量,寄存器变量)[转]

    c语言中变量分为四类,分别是 1.auto   自动变量 2.static   静态存贮分配变量(又分为内部静态和外部静态) 3.extern  全程变量(用于外部变量说明) 4.register   ...