Bzoj 4325:noip2015 Bucket Landlord

Source: Internet
Author: User

4325:noip2015 bucket landlord time limit:30 Sec Memory limit:1024 MB
submit:684 solved:456
[Submit] [Status] [Discuss] 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

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

Next T Group of data, each set of data n rows, a non-negative integer to Ai,bi, each line represents a card, wherein the AI represents the card 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

A total of T-lines, one integer per line, indicating the minimum number of times to hit a group of hands.

Sample Input1 8
7 4
8 4
9 1
10 4
11 1
5 1
1 4
1 1
Sample Output3HINT

There are 1 groups of hands, including 8 cards: Square 7, Square 8, spades 9, square piece 10, Spades J, Spades 5, Square


Slice A and spades a. Can be played by Tanshong (Square 7, Square 8, Spades 9, Square 10, Spades j), single sheet
The Card (spades 5) and the pair (spades A and square a) are light within 3 times.

t<=10
N<=23

Source [Submit] [Status] [Discuss]

Analysis

Search for good questions.

Code
1#include <bits/stdc++.h>2 intM, N, p[ -], c[ -], ans;3 Const intto[ -] = {0, -,1,2,3,4,5,6,7,8,9,Ten, One, A};4 intCalcvoid) {5Registerintres =0;6Memset (c,0,sizeof(c));7      for(inti =0; I <= -; ++i) + +C[p[i]];8      while(c[4] >0&& c[2] >1) c[4] -=1, c[2] -=2, ++Res;9      while(c[4] >0&& c[1] >1) c[4] -=1, c[1] -=2, ++Res;Ten      while(c[4] >0&& c[2] >0) c[4] -=1, c[2] -=1, ++Res; One      while(c[3] >0&& c[2] >0) c[3] -=1, c[2] -=1, ++Res; A      while(c[3] >0&& c[1] >0) c[3] -=1, c[1] -=1, ++Res; -     returnRes + c[1] + c[2] + c[3] + c[4]; - } the voidSearchints) { -     if(s >= ans)return; -Ans = std::min (ans, s +calc ()); -      for(inti =2, POS, tot; I <= -; ++i) +          for(intj =1; J <=3; ++J)if(P[i] >=j) { -              for(pos = i, tot =0; P[pos] >= J; ++pos) P[pos]-= j, tot + =J; +              for(;--pos >= i; P[pos] + = j, tot-= j)if(Tot >=5) Search (S +1); A         } at } -Signed Main (void) { -scanf"%d%d", &m, &n); -      while(m--) { -Memset (P,0,sizeof(P)); -          for(inti =1, X, y; I <= N; ++i) inscanf"%d%*d", &x), + +P[to[x]]; -Ans = -, Search (0), printf ("%d\n", ans); to     } +}
Noip_ bucket landlord. cpp

@Author: Yousiki

Bzoj 4325: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.