ktv
来源:互联网 发布:金字塔 java 编辑:程序博客网 时间:2024/06/09 20:02
Description
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 integer n (0 < n < 81), the number of possible combinations. The next n lines each contains 4 positive integers a, b, c, s (1 <= a < b < c <= 9, 0 < s < 10000), that means a score of s 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
一直没有看清题意,回溯.
就是找出几个中最大值,对应
a[],b[],c[]
回溯
当step==3,访问过了就退出.
max不能再全局变量中定义
#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>#include<cstring>using namespace std;struct xys{int x,y,z,s;}a[90];int v[100];int maxx=-1;void dfs(int step,int num,int sum){if(step==3){if( num > maxx )maxx = num;return;}for(int i=0;i<sum;i++){if( !v[a[i].x] && !v[a[i].y] && !v[a[i].z] ){v[a[i].x] = v[a[i].y] = v[a[i].z] = 1;dfs( step+1, num+a[i].s ,sum);v[a[i].x] = v[a[i].y] = v[a[i].z] = 0;}}}int main(){int time=0;memset(v,0,sizeof(v));int n;while(scanf("%d",&n)){if(n==0)break; for(int i=0;i<n;i++) {scanf("%d%d%d%d",&a[i].x,&a[i].y,&a[i].z,&a[i].s);//读数据 } dfs(0,0,n); printf("Case %d: %d\n", ++time, maxx );maxx=-1;}}
- KTV
- ktv
- KTV
- KTV
- KTV室内设计 KTV装修设计 KTV设计图
- 212KTV
- 北京KTV
- 麦颂KTV
- ktv唱歌
- 11218 - KTV
- uva11218 - KTV
- UVaOJ11218 - KTV
- 酷姿乐汇量贩式KTV
- ktv 系统设计经验
- ktv 系统设计经验
- 北京著名KTV
- UVa 11218 KTV
- KTV怎样保证客源
- C++中new delete 与malloc free的区别
- 外媒剖析东南亚移动游戏工业:印尼远景被看好
- android性能分析工具Profile GPU rendering详细介绍
- 通信
- 你好
- ktv
- 韩国沉没客轮上确认有两名中国人
- centos 6.5 64位 安装 vnc 远程桌面
- android 电话拨号程序
- Struts2中的设计模式
- 宋美龄“夫人干政”的两桩伪史
- java 操作数字证书(x509)
- Android Activity之间传递图片(Bitmap)的方法
- Bloom Filter