1. 程式人生 > >codeforces#247_div2_B Shower Line 暴力

codeforces#247_div2_B Shower Line 暴力

題目地址:點這裡

直接暴力列舉排列~

額.... 西安回來以後好久沒碰程式碼了..  寫一點簡單題解

程式碼:

#include<iostream>
#include<algorithm>

using namespace std;

int g[5][5];

int a[5];

typedef  long long  LL;


LL calc(int *p)
{
    LL ans=0;
    ans+=g[p[0]][p[1]]+g[p[1]][p[0]];
    ans+=2*(g[p[2]][p[3]]+g[p[3]][p[2]]);
    ans+=g[p[1]][p[2]]+g[p[2]][p[1]];
    ans+=2*(g[p[3]][p[4]]+g[p[4]][p[3]]);
    return  ans;
}

int main()
{
    for(int i=0;i<5;i++)
        for(int j=0;j<5;j++)
        {
            cin>>g[i][j];
            
        }
    
    for(int i=0;i<5;i++)
        a[i]=i;
    
    LL  max=-1;
    do{
        LL cur=calc(a);
        if(cur>max)
        {
            max=cur;
        }
    }
    while (next_permutation(a, a+5));
    
    cout<<max<<endl;
    
    
   
}