题意:9个人唱k,三个人一组,给出了n组数据,包括三个人和他们的可能得分,要求输出完全不同的三组得到总分最多的分数,如果没有完全不同的三组就也就是没有答案,输出-1;
题解:三层循环。。真的好暴力。。
#include <stdio.h>
#include <string.h>
const int N = 90;
int n, com[N][3], score[N], vis[10];
int main() {
int cases = 1;
while (scanf("%d", &n) && n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++)
scanf("%d", &com[i][j]);
scanf("%d", &score[i]);
}
memset(vis, 0, sizeof(vis));
int ans = -1;
for (int i = 0; i < n - 2; i++) {
vis[com[i][0]] = vis[com[i][1]] = vis[com[i][2]] = 1;
for (int j = i + 1; j < n - 1; j++) {
if (!vis[com[j][0]] && !vis[com[j][1]] && !vis[com[j][2]]) {
vis[com[j][0]] = vis[com[j][1]] = vis[com[j][2]] = 1;
for (int k = j + 1; k < n; k++) {
if (!vis[com[k][0]] && !vis[com[k][1]] && !vis[com[k][2]])
if (score[i] + score[j] + score[k] > ans)
ans = score[i] + score[j] + score[k];
}
vis[com[j][0]] = vis[com[j][1]] = vis[com[j][2]] = 0;
}
}
vis[com[i][0]] = vis[com[i][1]] = vis[com[i][2]] = 0;
}
printf("Case %d: %d\n", cases++, ans);
}
return 0;
}