题意:给出五个人的编号,分别为 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,算出每一种排列的交谈值,找出最大值

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include <cmath>
 5 #include<stack>
 6 #include<vector>
 7 #include<map>
 8 #include<set>
 9 #include<queue>
10 #include<algorithm>
11 using namespace std;
12
13 typedef long long LL;
14 const int INF = (1<<30)-1;
15 const int mod=1000000007;
16 const int maxn=100005;
17
18 int g[15][15];
19
20 int main(){
21     int n,a[10]={1,2,3,4,5};
22     n=5;
23     int p[10];
24
25     for(int i=1;i<=5;i++)
26      for(int j=1;j<=5;j++) cin>>g[i][j];
27
28     int ans=0;
29     int maxx=-1;
30     do{
31         for(int i=0;i<5;i++) {
32         //    printf("%d ",a[i]);
33             p[i]=a[i];
34         }
35
36         //    printf("\n");
37         int a=g[p[0]][p[1]]+g[p[1]][p[0]]+g[p[2]][p[3]]+g[p[3]][p[2]];
38         int b=g[p[1]][p[2]]+g[p[2]][p[1]]+g[p[3]][p[4]]+g[p[4]][p[3]];
39         int c=g[p[2]][p[3]]+g[p[3]][p[2]];
40         int d=g[p[3]][p[4]]+g[p[4]][p[3]];
41         ans=a+b+c+d;
42         maxx=max(ans,maxx);
43     //    printf("maxx=%d\n",maxx);
44     //    printf("ans=%d\n",ans);
45
46     } while(next_permutation(a,a+5));
47
48     printf("%d\n",maxx);
49     return 0;
50 }

View Code

转载于:https://www.cnblogs.com/wuyuewoniu/p/4445252.html

codeforces 431 B Shower Line【暴力】相关推荐

  1. Codeforces gym 100685 A. Ariel 暴力

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

  2. [ An Ac a Day ^_^ ] CodeForces 691F Couple Cover 花式暴力

    Couple Cover Time Limit: 3000MS   Memory Limit: 524288KB   64bit IO Format: %I64d & %I64u Descri ...

  3. Educational Codeforces Round 12 B. Shopping 暴力

    B. Shopping 题目连接: http://www.codeforces.com/contest/665/problem/B Description Ayush is a cashier at ...

  4. Codeforces 460E Roland and Rose(暴力)

    题目链接:Codeforces 460E Roland and Rose 题目大意:在以原点为圆心,半径为R的局域内选择N个整数点,使得N个点中两两距离的平方和最大. 解题思路:R最大为30.那么事实 ...

  5. 枚举 ---- B. Power Sequence[Codeforces Round #666 (Div. 2)][暴力]

    B. Power Sequence 有 n 个数,现在要求将这个数列变成一个等比数列的形式 你可以将这 n 个数随意排列 或者将任意一个数加一或者减一操作,每次此类操作都要花费 1,问最少花费是多少 ...

  6. Codeforces 1138B Circus (构造方程+暴力)

    题意: 给你两个01串,要你选n/2个位置,使得选的位置在s1中"1"的数量等于未选的s2中"1"的数量 n<=5000,1s 思路: 设两个串中出现&q ...

  7. CodeForces - 1457D XOR-gun(位运算+暴力)

    题目链接:点击查看 题目大意:给出一个长度为 n 的非降序列,现在可以执行数次操作:选择相邻的两个位置将其替换成异或和,更具体的,每次操作可以选择一个位置 i ,满足 1 <= i < n ...

  8. CodeForces - 993C Careful Maneuvering(几何+暴力+状态压缩)

    题目链接:点击查看 题目大意:在 x = -100 的直线上有 n 个敌方飞船,在 x = 100 的直线上有 m 个敌方飞船,现在在 x = 0 的直线上可以选择两个点作为诱饵,使得两侧的飞船瞄准射 ...

  9. CodeForces - 1293D Aroma's Search(暴力)

    题目链接:点击查看 题目大意:给出一个无限大小的二维平面坐标系,现在给出一系列数据点,给出的形式是给出(x[0],y[0]),再规定可以使用递推式x[i]=ax*x[i-1]+bx,y[i]=ay*y ...

最新文章

  1. 「人眼难以承受」的美丽,在地球之外看地球
  2. iOS沙盒路径及路径下数据的存储和读取
  3. Ethernet/IP 学习笔记四
  4. java实现压缩图片的方法
  5. 【TypeScript系列教程06】基础类型
  6. 《搭建Centos7之一》
  7. mbot编程机器人怎么连接蓝牙_台式机蓝牙怎么连接
  8. 【洛谷P1774】最接近神的人_NOI导刊2010提高(02)(模版题---求逆序对数目+离散化---树状数组/权值线段树)
  9. Python基础 4 字符串的变形 判断
  10. QWERT切换到DVORAK
  11. 「现场参会攻略」| 2018AI in China之智能制造数据驱动产业变革高峰论坛
  12. 理解MVC、MVP、MVVM在干什么,进化的原因。
  13. springboot整合redis,redisTemplate 空指针
  14. 两个独立同分布的指数分布相加服从什么分布
  15. jsp简介及工作原理
  16. R语言学习手记 (1)
  17. 安科瑞“智慧用电”一个适合高校学生公寓安全用电的智能控制与管理系统
  18. 事务的隔离 transaction isolation
  19. C语言查找奥运五环色的位置
  20. uniapp开发,打包成H5部署到服务器

热门文章

  1. python gui下载进度条_对python GUI实现完美进度条的示例详解
  2. maven jersey mysql_使用Maven和Jersey Framework开发REST风格Web Service
  3. android6.0原生brower_android原生browser分析(二)--界面篇
  4. [python]python urllib 模块
  5. Python 初始篇
  6. 算法笔记--无向图的桥、割点、边双连通分量和点双连通分量
  7. 一起来学Masonry (一)
  8. 使用Asp.net MVC 2.0 +.NET 4.0 出现 “从客户端 ... 中检测到有潜在危险的 Request.Form 值”错误的解决办法...
  9. php : 匿名函数(闭包) [一]
  10. 如何拉起被一键清除的安卓进程