码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 431 B Shower Line【暴力】

时间:2015-04-21 20:29:48      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

题意:给出五个人的编号,分别为 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

 

codeforces 431 B Shower Line【暴力】

标签:

原文地址:http://www.cnblogs.com/wuyuewoniu/p/4445252.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!