模拟即可
#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; }
Codeforces Round #247 (Div. 2) B - Shower Line,布布扣,bubuko.com
时间: 2024-10-21 02:28:12