zoukankan      html  css  js  c++  java
  • End up with More Teams UVA

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

    []   [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

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <algorithm>
     5 using namespace std;
     6 int a[20],b[20],n,m,maxa;
     7 bool cmp(int x,int y)
     8 {
     9     return x>y;
    10 }
    11 void dfs(int x,int cur)
    12 {
    13     int i,j,k,sum;
    14     if(maxa<cur)maxa=cur;
    15     if(maxa==m)
    16         return;
    17     for(i=x; i<n; i++)
    18     {
    19         if(!b[i])
    20             for(j=i+1; j<n; j++)
    21             {
    22                 if(!b[j])
    23                 {
    24                     sum=a[i]+a[j];
    25                     for(k=j+1; k<n; k++)
    26                     {
    27                         if(!b[k]&&sum+a[k]>=20)break;
    28                     }
    29                     if(k<n)
    30                     {
    31                         b[i]=b[j]=b[k]=1;
    32                         dfs(i+1,cur+1);
    33                         b[i]=b[j]=b[k]=0;
    34                     }
    35                 }
    36             }
    37     }
    38 }
    39 int main()
    40 {
    41     int i,cas=1;
    42     while(~scanf("%d",&n),n)
    43     {
    44         maxa=0;
    45         memset(b,0,sizeof(b));
    46         for(i=0; i<n; i++)scanf("%d",&a[i]);
    47         sort(a,a+n);
    48         m=n/3;
    49         dfs(n%3,0);
    50         printf("Case %d: %d
    ",cas++,maxa);
    51     }
    52 }
    View Code
  • 相关阅读:
    BZOJ 4032: [HEOI2015]最短不公共子串 (dp*3 + SAM)
    后缀自动机详解!
    BZOJ 3926: [Zjoi2015]诸神眷顾的幻想乡(广义后缀自动机 多串)
    BZOJ 3938 Robot
    [JSOI2008]Blue Mary开公司
    [ZJOI2017]树状数组
    [JSOI2015]非诚勿扰
    [HNOI2011]任务调度
    BZOJ 3680 吊打XXX
    POJ 3318 Matrix Multiplication
  • 原文地址:https://www.cnblogs.com/ERKE/p/3675023.html
Copyright © 2011-2022 走看看