Topic description
This question is a fill-in-the-blank question. After calculating the result, use the output statement in the code to output the filled result.
As a basketball coach, you'll need to select one player from the list below from positions 1 to 5 to form the team's starting lineup.
The ratings for each player in positions 1 to 5 are shown in the table below. Can you calculate the maximum possible sum of the ratings of the starting lineup's No. 1 to No. 5?
dfs+pruning
Always keep in mind the location of the restoration site
#include <iostream>
#include <algorithm>
using namespace std;
bool st[25];
int ans = -2e9;
int g[5][20] = {
{
97, 92, 0, 0, 89, 82, 0, 0, 0, 95, 0, 0, 94, 0, 0, 0, 98, 93, 0, 0},
{
90, 85, 0, 0, 83, 86, 0, 97, 0, 99, 0, 0, 91, 83, 0, 0, 83, 87, 0, 99},
{
0, 96, 0, 0, 97, 0, 0, 96, 89, 0, 96, 0, 0, 87, 98, 0, 99, 92, 0, 96},
{
0, 0, 0, 80, 0, 0, 87, 0, 0, 0, 97, 93, 0, 0, 97, 93, 98, 96, 89, 95},
{
0, 0, 93, 86, 0, 0, 90, 0, 0, 0, 0, 98, 0, 0, 98, 86, 81, 98, 92, 81}
};
int temp = 0;
void dfs(int u) {
if (u == 5) {
ans = max(ans, temp);
return;
}
for (int i = 0; i < 20; i++) {
if (!st[i] && g[u][i]) {
temp += g[u][i];
st[i] = true;
dfs(u+1);
temp -= g[u][i]; // ***
st[i] = false;
}
}
}
int main()
{
// 请在此输入您的代码
dfs(0);
cout << ans << endl;
return 0;
}