uva 11218 - KTV
来源:互联网 发布:邮差总按两次铃 在线vb 编辑:程序博客网 时间:2024/06/11 01:36
Problem K
KTV
One song is extremely popular recently, so you and your friends decided to sing it in KTV. The song has 3 characters, so exactly 3 people should sing together each time (yes, there are 3 microphones in the room). There are exactly 9 people, so you decided that each person sings exactly once. In other words, all the people are divided into 3 disjoint groups, so that every person is in exactly one group.
However, some people don't want to sing with some other people, and some combinations perform worse than others combinations. Given a score for every possible combination of 3 people, what is the largest possible score for all the 3 groups?
Input
The input consists of at most 1000 test cases. Each case begins with a line containing a single integern (0 <n < 81), the number of possible combinations. The next n lines each contains 4 positive integersa, b, c,s (1 <= a < b < c <= 9, 0 < s < 10000), that means a score ofs is given to the combination (a,b,c). The last case is followed by a single zero, which should not be processed.Output
For each test case, print the case number and the largest score. If it is impossible, print -1.Sample Input
31 2 3 14 5 6 27 8 9 341 2 3 11 4 5 21 6 7 31 8 9 40
Output for the Sample Input
Case 1: 6Case 2: -1#include <string.h>#include <stdio.h>struct node{int a,b,c,score;}s[100];int n,visit[10],max;void dfs(int num,int step,int sum){ if (step>3) {if (sum>max) max=sum; return ;} if (num>n) return ; if (visit[s[num].a]+visit[s[num].b]+visit[s[num].c]==0) {visit[s[num].a]=1; visit[s[num].b]=1; visit[s[num].c]=1; dfs(num+1,step+1,sum+s[num].score); visit[s[num].a]=0; visit[s[num].b]=0; visit[s[num].c]=0; } dfs(num+1,step,sum);};int main(){int i,Case=0; while (scanf("%d",&n),n) { memset(visit,0,sizeof(visit)); max=-1; ++Case; for (i=1;i<=n;i++) scanf("%d%d%d%d",&s[i].a,&s[i].b,&s[i].c,&s[i].score); dfs(1,1,0); printf("Case %d: %d\n",Case,max); } return 0;}
- UVa 11218 KTV
- UVA 11218 - KTV
- uva 11218 - KTV
- uva 11218 - KTV
- UVa 11218 - KTV
- Uva 11218 - KTV
- uva 11218 KTV(DFS)
- UVA 11218 - KTV DFS
- uva 11218 KTV
- uva 11218 - KTV
- UVa 11218—KTV
- UVa 11218 - KTV
- UVa 11218 - KTV
- uva 11218 - KTV 简单回溯
- UVA 11218 KTV 深搜+回溯
- uva 11218 KTV(DFS+回溯)
- UVa 11218 KTV (枚举&位运算)
- UVA - 11218 KTV(暴力求解)
- 内存管理
- 轻量级的C语言面向对象编程框架
- 文件系统API函数
- 互联网老兵:第一代程序员简晶 最老站长华军
- Android APK反编译详解(附图)
- uva 11218 - KTV
- 个人收录的各种命名法(只是我个人所知道的一些)
- Linux压缩命令
- Android 中的Parcelable与Serializalbe
- 波峰焊与回流焊的区别
- WTL 中使用GDI+ 备忘 (博客园个人笔记)
- 08-15
- 基于S3C2440的嵌入式Linux驱动——SPI子系统解读(一)
- 设计师分享小贴士:避免使用黑色