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

OpenSoucre發表於2014-06-13

模擬即可

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    vector<int> a(5);
    for(int i = 0; i < 5; ++ i) a[i] = i;
    int g[5][5];
    for(int i = 0 ; i < 5; ++ i){
        for(int j = 0 ; j < 5; ++ j){
            cin >> g[i][j];
        }
    }
    int maxHappiness = 0;
    do{
        maxHappiness = max(g[a[1]][a[0]]+g[a[0]][a[1]]+g[a[3]][a[2]]+g[a[2]][a[3]]+g[a[2]][a[1]]+g[a[1]][a[2]]+g[a[4]][a[3]]+g[a[3]][a[4]]+g[a[3]][a[2]]+g[a[2]][a[3]]+g[a[4]][a[3]]+g[a[3]][a[4]],maxHappiness);
        cout<<a[0]<<a[1]<<a[2]<<a[3]<<a[4]<<endl;
        cout<<maxHappiness<<endl;
        
    }while(next_permutation(a.begin(),a.end()));
    cout<<maxHappiness<<endl;
    
}

 

相關文章