Noip2015 Bucket Landlord

Source: Internet
Author: User

P2668 Bucket Landlord
      • 291 through
      • 2.5K Submit
    • Topic provider Rokua Onlinejudge
    • Tag search/Enumerate Noip raise group
    • Difficulty Increase +/province selection-

Submit a discussion of the problem record

Recent discussions
    • There's an unknown error, that's a terrier.
    • 30 min soy sauce
    • No watermark version
Title Description

Niuniu recently got hooked on a poker game called the Landlord. A bucket landlord is a poker game that uses spades, hearts, plum blossoms, square pieces of a to K plus a total of 54 cards of the king's size. In the bucket landlord, the size of the card is based on the digital representation of the following:3<4<5<6<7<8<9<10<j<q<k<a<2< Xiao Wang < king, And the color does not affect the size of the card. In each game, a second hand is made up of n cards. Each time the player can play according to the prescribed card type, first of all to light their own hand to win the game.

Now, cattle and cows just want to know, for their own group of hands, the minimum number of times required to play the cards can be light. Please help him to solve the problem.

It is important to note that the players in the subject can be shot each time the card type and the general landlords similar and slightly different.

The specific rules are as follows:

Input output Format input format:

The first line contains 2 positive integer tn separated by spaces, indicating the number of groups of hands and the number of cards per group.

Next T set of data, each set of data n rows, a non-negative integer per line of Aibi represents a card, where AI signs of the digital, BI represents the color of the card, the middle with a space separated. In particular, we use one of the digital a,11 said Digital j,12 said digital q,13 mean digital K, spades, hearts, plum, square slices respectively with 1-4 to express; Xiao Wang's expression method is 01, the King's expression method is 02.

Output format:

A total of T-lines, one integer per line, indicating the minimum number of times to hit the first hand.

Input and Output Sample input example # #:
1 87 48 49 110 411 15 11 41 1
Sample # # of output:
3
Input Sample #:
1 1712 34 32 35 410 23 312 20 11 310 16 212 111 35 212 42 27 2
Output Example #:
6
Description

Example 1 description

There are 1 groups of hands, including 8 cards: Square 7, Square 8, Spades 9, Fang Pian 10, Spades J, Spades 5, square A and spades a. Can be played by Tanshong (Square 7, Square 8, Spades 9, Square 10, Spades J), a single card (spades 5) and a pair of cards (spades A and square a) within 3 times to light.

For different test points, we agreed that the size of the hand group T and the number of n is as follows:

Data assurance: All hand cards are randomly generated.

Analysis: Re-do this problem, full of tears, in the examination room played a 30 points of violence, the results of 0 burst ... Step into the subject, this problem a look will know is definitely a bomb search, but the situation is too much, how to do? Notice that the impact on the number of times is straight, if not hit the son, then the minimum number of cards is certain, so DFS search out the three straight sub-CIS and the total number of steps after the child, and then update the answer. The color is useless in the subject.

#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;Const intMAXN = -;intA[MAXN], NUM[MAXN];intN, t, ans;intChupai () {memset (num,0,sizeof(num));  for(inti =0; I <= -; i++) Num[a[i]]++; inttot =0;  while(num[4] && num[2] >1) {num[4]--; num[2] -=2; Tot++; }     while(num[4] && num[1] >1) {num[4]--; num[1] -=2; Tot++; }     while(num[4] && num[2]) {num[4]--; num[2]--; Tot++; }     while(num[3] && num[2]) {num[3]--; num[2]--; Tot++; }     while(num[3] && num[1]) {num[3]--; num[1]--; Tot++; }    returnTot + num[1] + num[2] + num[3] + num[4];}voidDfsintStep) {    if(Step >=ans)return; inttemp =Chupai (); if(Temp + Step <ans) ans= temp +step;  for(inti =2; I <= -; i++)    {        intj =i;  while(A[j] >=3) J++; if(J-i >=2)        {             for(intJ2 = i +1; J2 <= J-1; j2++)            {                 for(intK = i; K <= J2; k++) A[k]-=3; DFS (step+1);  for(intK = i; K <= J2; k++) A[k]+=3; }        }    }     for(inti =2; I <= -; i++)    {        intj =i;  while(A[j] >=2) J++; if(J-i >=3)        {             for(intJ2 = i +2; J2 <= J-1; j2++)            {                 for(intK = i; K <= J2; k++) A[k]-=2; DFS (step+1);  for(intK = i; K <= J2; k++) A[k]+=2; }        }    }     for(inti =2; I <= -; i++)    {        intj =i;  while(A[j] >=1) J++; if(J-i >=5)        {             for(intJ2 = i +4; J2 <= J-1; j2++)            {                 for(intK = i; K <= J2; k++) A[k]--; DFS (step+1);  for(intK = i; K <= J2; k++) A[k]++; }        }    }}intMain () {scanf ("%d%d", &t, &N);  while(t--) {memset (A,0,sizeof(a));  for(inti =1; I <= N; i++)        {            intx, y; scanf ("%d%d", &x, &y); if(x = =1)//Convert ax = -; Else            if(x) x--; A[X]++; } ans=1e9; DFS (0); printf ("%d\n", ans); }    return 0;}

Noip2015 Bucket Landlord

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.