Codeforces #247 (Div. 2) B. Shower Line
来源:互联网 发布:nhj提取软件 编辑:程序博客网 时间:2024/05/16 18:19
暴力题,知道下一个排列:next_permutation()就好做了
b[1]-b[5]为1-5的全排列
则找出b的所有全排列,计算sum = a[b[1]][b[2]] + a[b[2]][b[1]] + a[b[2]][b[3]] + a[b[3]][b[2]] + 2*a[b[3]][b[4]] + 2*a[b[4]][b[3]] + 2*a[b[4]][b[5]]+2*a[b[5]][b[4]];的最大值即可
代码如下:
#include <cstdio>#include <iostream>#include <algorithm>#define MAXN 110#define ll long longusing namespace std;int a[MAXN][MAXN];int b[MAXN];int main(void) { for(int i=1; i<=5; ++i) { for(int j=1; j<=5; ++j) { scanf("%d", &a[i][j]); } b[i] = i; } ll sum = a[b[1]][b[2]] + a[b[2]][b[1]] + a[b[2]][b[3]] + a[b[3]][b[2]] + 2*a[b[3]][b[4]] + 2*a[b[4]][b[3]] + 2*a[b[4]][b[5]]+2*a[b[5]][b[4]]; ll bestsum = sum; while(next_permutation(b+1, b+6)) { sum = a[b[1]][b[2]] + a[b[2]][b[1]] + a[b[2]][b[3]] + a[b[3]][b[2]] + 2*a[b[3]][b[4]] + 2*a[b[4]][b[3]] + 2*a[b[4]][b[5]]+2*a[b[5]][b[4]]; // cout << "sum = " << sum << endl; if(sum > bestsum) bestsum = sum; } cout << bestsum << endl; return 0;}
0 0
- Codeforces #247 (Div. 2) B. Shower Line
- Codeforces Round #247(Div. 2) B. Shower Line 暴力
- Codeforces Round #247 (Div. 2)a.Black Square,b.Shower Line,c.k-Tree前三题
- Codeforces Round #247 (Div. 2) B. Shower Line(简单模拟)
- codeforces 431B - Shower Line
- Codeforces 431B Shower Line
- codeforces 431B Shower Line
- codeforces 431B Shower Line
- codeforces#247_div2_B Shower Line 暴力
- B. Shower Line
- Shower Line
- Codeforces Round #247 (Div. 2) A B
- Codeforces Round #247 (Div. 2) B
- Codeforces Round #189 (Div. 1) B. Psychos in a Line
- Codeforces #261 Div 2 B
- codeforces #368 div.2B
- Codeforces--477Div.2--B
- Codeforces Round #131 (Div. 2) A B
- 第03章-VTK系统概述(1)
- android 程序优化之查错篇
- CCThread(On iOS, should create autorelease pool when create a new thread)
- PHP json_encode中文乱码解决方法--json乱码处理
- 4我回来了+安卓程序报错,无法启动的解决办法
- Codeforces #247 (Div. 2) B. Shower Line
- JDBC事务处理
- oracle数据连接情况及显示客户端IP
- CCSAXParser(可以用来读xml等)
- linux gz 解压缩
- CCPlatformMacros(平台宏 CREATE_FUNC USING_NS_CC CC_PROPERTY_READONLY等属性 CC_SAFE_DELETE)
- 我的Android心得(1)--一些常用资源
- 中国特色程序员的「钱途」
- CCImageCommonWebp