Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

[Submit]   [Go Back]   [Status]

Description

 

06

Problem E: End up with More Teams

Input: standard input

Output: standard output

The prestigious ICPC is here again. The coaches are busy selecting teams. Well this year, they have adopted a new policy. Contrary to traditional selection process, where few individual contests are held and the top three are placed in one team the next three in another and so on, this year the coaches decided to place members in such a way that the total number of promising teams is maximized. Promising teams are defined as a team having ability points of its members adding up to 20 or greater. Here ability point of a member denotes his capability as a programmer, the higher the better.

Input

There will be as many as 100 cases in the input file. Each case of input has two lines. The first line contains a positive integerwhere n indicates the number contestants available for selection. The next line will contain n positive integers, each of which will be at most 30.  End of input is indicated by a value of 0 forn.

Output

For every case of input there will be one line of output. This line should contain the case number followed by the maximum number of promising teams that can be formed. Note that it is not mandatory to assign everyone in a team. Incase you don’t know, each team consists of exactly 3 members.

Constraints

-           n ≤ 15

Sample Input

Output for Sample Input

9
22 20 9 10 19 30 2 4 16
2
15 3
0

Case 1: 3
Case 2: 0

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int a[],b[],n,m,maxa;
bool cmp(int x,int y)
{
return x>y;
}
void dfs(int x,int cur)
{
int i,j,k,sum;
if(maxa<cur)maxa=cur;
if(maxa==m)
return;
for(i=x; i<n; i++)
{
if(!b[i])
for(j=i+; j<n; j++)
{
if(!b[j])
{
sum=a[i]+a[j];
for(k=j+; k<n; k++)
{
if(!b[k]&&sum+a[k]>=)break;
}
if(k<n)
{
b[i]=b[j]=b[k]=;
dfs(i+,cur+);
b[i]=b[j]=b[k]=;
}
}
}
}
}
int main()
{
int i,cas=;
while(~scanf("%d",&n),n)
{
maxa=;
memset(b,,sizeof(b));
for(i=; i<n; i++)scanf("%d",&a[i]);
sort(a,a+n);
m=n/;
dfs(n%,);
printf("Case %d: %d\n",cas++,maxa);
}
}

End up with More Teams UVA - 11088的更多相关文章

  1. Teams UVA - 11609

    题意就不多说了这个小规律不算难,比较容易发现,就是让你求一个数n*2^(n-1):很好想只是代码实现起来还是有点小困(简)难(单)滴啦,一个快速幂就OK了: 代码: #include<stdio ...

  2. Teams UVA - 11609(快速幂板题)

    写的话就是排列组合...但能化简...ΣC(n,i)*C(i,1) 化简为n*2^(n-1) ; #include <iostream> #include <cstdio> # ...

  3. uva 11088 暴力枚举子集/状压dp

    https://vjudge.net/problem/UVA-11088 对于每一种子集的情况暴力枚举最后一个三人小组取最大的一种情况即可,我提前把三个人的子集情况给筛出来了. 即 f[S]=MAX{ ...

  4. UVA 11609 Teams 组合数学+快速幂

    In a galaxy far far away there is an ancient game played among the planets. The specialty of the gam ...

  5. uva 10911 - Forming Quiz Teams(记忆化搜索)

    题目链接:10911 - Forming Quiz Teams 题目大意:给出2 * n个选手的坐标, 要求将所有的选手分成n组, 每组两个人, 所有组的两个人之间的距离之和要最小, 输出最小值. 解 ...

  6. UVA 10911 Forming Quiz Teams(dp + 集合最优配对问题)

    4th IIUC Inter-University Programming Contest, 2005 G Forming Quiz Teams Input: standard input Outpu ...

  7. UVA - 11609 Teams (排列组合数公式)

    In a galaxy far far awaythere is an ancient game played among the planets. The specialty of the game ...

  8. UVA 11609 - Teams(二项式系数)

    题目链接 想了一会,应该是跟二项式系数有关系,无奈自己推的式子,构不成二项式的系数. 选1个人Cn1*1,选2个人Cn2*2....这样一搞,以为还要消项什么的... 搜了一下题解,先选队长Cn1,选 ...

  9. UVa 11609 (计数 公式推导) Teams

    n个人里选k个人有C(n, k)中方法,再从里面选一人当队长,有k中方法. 所以答案就是 第一步的变形只要按照组合数公式展开把n提出来即可. #include <cstdio> typed ...

随机推荐

  1. sizeof(void)有什么用

    偶然发现在C中sizeof(void)是合法的,于是,对它的作用产生了疑问.查阅资料在GNU文档中发现如下解释: In GNU C, addition and subtraction operatio ...

  2. 基于redis的延迟消息队列设计

    需求背景 用户下订单成功之后隔20分钟给用户发送上门服务通知短信 订单完成一个小时之后通知用户对上门服务进行评价 业务执行失败之后隔10分钟重试一次 类似的场景比较多 简单的处理方式就是使用定时任务 ...

  3. AOP TP框架有感

    自学AOP感觉面向切面编程是一种利器,同时也是一种潜在的威胁.他就像一把手术刀,无论哪个器官有问题他都可以把他切开,修复它,但是使用的多了身体也会受不了... AOP应该算是面向对象的一种补充,但是, ...

  4. OSX 10.8+下开启Web 共享 的方法

    MENU Home Archives About SUBSCRIBE ☰MENU OSX 10.8+ Mountain Lion 下开启 Web Sharing(Web 共享)的方法 JUL 28, ...

  5. 【集美大学1411_助教博客】团队作业8——第二次项目冲刺(Beta阶段)

    写在前面的话 此次团队作业8可以拆分成两部分:1.beta阶段冲刺计划安排,2.7天敏捷冲刺."我们很低调"没有使用leangoo,经过与张老师的商议,张老师同意他们不使用lean ...

  6. 团队作业4——第一次项目冲刺(Alpha版本) 4.24

    团队作业4--第一次项目冲刺(Alpha版本) Day four: 会议照片 每日站立会议: 项目进展 今天是项目的Alpha敏捷冲刺的第三天,先大概整理下昨天已完成的任务以及今天计划完成的任务.今天 ...

  7. 201521123032 《Java程序设计》第8周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 2. 书面作业 本次作业题集集合 1.List中指定元素的删除(题目4-1) 1.1 实验总结 在课堂上在老师 ...

  8. 201521123121 《JAVA程序设计》第8周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 所有泛型方法声明都有一个类型参数声明部分(由尖括号分隔),该类型参数声 ...

  9. 201521123006 《java程序设计》 第12周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...

  10. Eclipse rap 富客户端开发总结(9) : rap上传与下载

    一 上传 上传即将文件上传到服务器上,在客户端需要写相应的脚本,服务器端需要注册相应的 handle 接受客户端的请求. 原理: Rap 的上传和下载是通过普通的 web 的方式进行上传和下载的 ,  ...