题目链接
解题思路:这题看上去怪吓人,其实就是暴力求解,把每种情况遍历一下比较即可。因为它只有5个位置,每个位置20个人,也就是遍历20^5,暴力求解还是能通过的,代码如下。
//组队
#include
#include
int main(int argc, char *argv[])
{
// 请在此输入您的代码
int i, j, k, l, m;//分别标记1-5号位的各个选手,比如i标记1号位的1-20个选手
int arr[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}
};//arr[a][b]表示a+1号位,b号选手的评分,比如arr[0][9]为1号位9号选手评分
int max = 0;
for (i = 0;i < 20;i++)
{
for (j = 0;j < 20;j++)
{
for (k = 0;k < 20;k++)
{
for (l = 0;l < 20;l++)
{
for (m = 0;m < 20;m++)
{
//要保证一个选手只能担任一个位置
if (i != j && i != k && i != l && i != m && j != k && j != l && j != m && k != l && k != m && l != m)
{
int tmp = arr[0][i] + arr[1][j] + arr[2][k] + arr[3][l] + arr[4][m];
if (tmp > max)
{
max = tmp;
}
}
}
}
}
}
}
printf("%d", max);
return 0;
}