Codeforces Round #247 (Div. 2) B - Shower Line
模拟即可
#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; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步