zoukankan      html  css  js  c++  java
  • codeforces 431 B Shower Line【暴力】

    题意:给出五个人的编号,分别为 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("
    ");
    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
    ",maxx);
    44     //    printf("ans=%d
    ",ans);
    45     
    46     } while(next_permutation(a,a+5));
    47     
    48     printf("%d
    ",maxx);
    49     return 0;
    50 }
    View Code
  • 相关阅读:
    MySQL--06
    MySQL--05
    MySQL--04
    MySQL--03
    MySQL--02
    MySQL--01
    JavaScript3
    JavaScript2
    四大函数式接口 函数型接口 断定型接口 消费型接口 供给型接口 流式计算
    课后作业-阅读任务-阅读提问-4
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4445252.html
Copyright © 2011-2022 走看看