组队 - 蓝桥云课 (lanqiao.cn)
题目描述
方法一:由肉眼观察找到在一至五号位的不同编号成员的最大的值
#include<bits/stdc++.h>
using namespace std;
int main()
{cout << 98 + 99 + 98 + 97 + 98;return 0;
}
方法二:由dfs一一找寻
#include<bits/stdc++.h>
using namespace std;
const int N = 2e4 + 10;
int ans, a[N][N], v[N];
void dfs(int num, int sum)
{if(num > 5){ans = max(ans, sum);//cout << ans << '\n';return;}for(int i = 1; i <= 20; i ++){if(v[i] == 0){v[i] = 1;dfs(num + 1, sum + a[i][num]);v[i] = 0;}}
}
int main()
{for(int i = 1; i <= 20; i ++){for(int j = 1; j <= 5; j ++){cin >> a[i][j];}}dfs(0, 0);//从第一个位置开始,现在的分数为0 cout << ans;return 0;
}
/*
97 90 0 0 0
92 85 96 0 0
0 0 0 0 93
0 0 0 80 86
89 83 97 0 0
82 86 0 0 0
0 0 0 87 90
0 97 96 0 0
0 0 89 0 0
95 99 0 0 0
0 0 96 97 0
0 0 0 93 98
94 91 0 0 0
0 83 87 0 0
0 0 98 97 98
0 0 0 93 86
98 83 99 98 81
93 87 92 96 98
0 0 0 89 92
0 99 96 95 81*/