luogu2540 Bucket Landlord Enhanced Edition

Source: Internet
Author: User

Main topic

Give you a hand, no plane with wings, according to the rules of the landlord, the minimum number of cards to be played.

The first is not considering the straight

We already know that the color of the card does not affect, then if not consider the straight, each card specific what number we do not need to know, we are concerned about only the card heap in the single, pair, stick, bombs, the number of kings. So we can use $f (k_1,k_2,k_3,k_4,k_x) $ to indicate when there are $k_1$ leaflets, $k _2$ pairs, $k _3$ a stick, $k _4$ a bomb, $k _x$ a king, the cards are all played the minimum number of times. And obviously it's possible to do DP. The transfer mode is: either do not open the card and the card, or the demolition of the card.

The order of recursion?

Take a look at the following split-card recursion:

                        if (K2)//Two is split into two single                            updmin (cur, f[k1 + 2][k2-1][k3][k4][kx]);                        if (K3)//will three split into a single sheet and a pair                            of updmin (cur, f[k1 + 1][k2 + 1][k3-1][k4][kx]);                        if (K4)//split four into a single sheet and a stick                            updmin (cur, f[k1 + 1][k2][k3 + 1][k4-1][kx]);                        if (K4)//Four is split into two pairs                            updmin (cur, f[k1][k2 + 2][k3][k4-1][kx]);            

We consider it from the outside. The outermost layer cannot be shifted from + 1, so we select the $k_4$ as the outermost layer. At this point, the transfer from the $k_4-1$ is legal, we look at the transfer from the $k_4$, the second layer can not be transferred from + 1. Therefore, the second floor selected $k_3$. At this point, the transfer from the $k3-1$ is legal. When transferring from $k_3$, the third layer cannot be transferred from + 1 ... Therefore, the recursion order is $k_4\rightarrow K_3\rightarrow k_2\rightarrow k_1\rightarrow k_x$.

Think of a straight son?

Enumerate all the way out of the straight (violent search), and then in the remaining cards to check the DP table.

#include <cstdio> #include <cstring> #include <algorithm> #include <cassert>using namespace std ; #define Updmin (x, y) x = min (x, y) const int max_id = MAX_IDCNT = 7, INF = 0x3f3f3f3f;const int idbegin = 1, Idshunzie nd = Idlast = 5, Maxunitlen = 3;const int unitcnt[4] = {0, 3, 2};int f[max_id][max_id][max_id][max_id][max_id];i NT IDCNT[MAX_ID], Idcnt_cnt[max_idcnt];int cardcnt, ans;void doshunzi (int shunzicnt, int idbegin, int unitLen, int unitCnt    {if (shunzicnt >= Ans) return;    for (int do = 0; do < unitcnt; did++) Idcnt[idbegin + did]-= Unitlen;    memset (idcnt_cnt, 0, sizeof (idcnt_cnt));    for (int id = idbegin; ID <= idlast; id++) idcnt_cnt[idcnt[id]]++; Idcnt_cnt[0] = idcnt[0];    Updmin (Ans, shunzicnt + f[idcnt_cnt[1]][idcnt_cnt[2]][idcnt_cnt[3]][idcnt_cnt[4]][idcnt_cnt[0]); for (int unitLen1 = 1, unitLen1 <= idlast; unitlen1++) for (int idBegin1 = idbegin; idBegin1 <= idshunziend; idbegin1++)            for (int unitCnt1 = 1; idBegin1 + unitcnt1-1 <= idshunziend && idcnt[idbegin1 + unitcnt1-1] ; = UnitLen1; unitcnt1++) if (unitCnt1 >= unitcnt[unitlen1]) Doshunzi (shunzicnt + 1, idBegin1, unit    Len1, UnitCnt1); for (int do = 0; do < unitcnt; did++) Idcnt[idbegin + did] + = Unitlen;}    void DP () {memset (f, INF, sizeof (f));    F[0][0][0][0][0] = 0; for (int K4 = 0, K4 <= CARDCNT/4; k4++) for (int K3 = 0, K3 <= CARDCNT/3; k3++) for (int k2 = 0; K2 <= CARDCNT/2;                    k2++) for (int k1 = 0, K1 <= cardcnt; k1++) for (int kx = 0; KX <= 2; kx++)                        {int &cur = F[k1][k2][k3][k4][kx];                        if (KX >= 2)//Rocket updmin (cur, f[k1][k2][k3][k4][kx-2] + 1);       if (K4)//Bomb updmin (cur, f[k1][k2][k3][k4-1][kx] + 1);                 if (K1)//leaflet, not Wang Updmin (cur, f[k1-1][k2][k3][k4][kx] + 1);                        if (KX)//leaflet, is Wang Updmin (cur, f[k1][k2][k3][k4][kx-1] + 1);                        if (K2)//Pair updmin (cur, f[k1][k2-1][k3][k4][kx] + 1);                        if (K3)//three sheets updmin (cur, f[k1][k2][k3-1][k4][kx] + 1);                        if (K3 && K1)//Three with one, one is not Wang Updmin (cur, f[k1-1][k2][k3-1][k4][kx] + 1);                        if (K3 && kx)//Three with one, one is Wang Updmin (cur, f[k1][k2][k3-1][k4][kx-1] + 1); if (K3 && K2)//Three bands two, two are not King Updmin (cur, f[k1][k2-1][k3-1][k4][kx] + 1                        );                        if (K4 && K1 >= 2)//Four with two single, two are not King Updmin (cur, f[k1-2][k2][k3][k4-1][kx] + 1); if (K4 && K1&& kx)//Four with two single, two in one is not king, one is Wang Updmin (cur, f[k1-1][k2][k3][k4-1][kx-1] + 1); if (K4 && K2 >= 2)//Four with two pairs of updmin (cur, f[k1][k2-2][k3][k4-1][kx] +                        1);                        if (K2)//Two is split into two single updmin (cur, f[k1 + 2][k2-1][k3][k4][kx]);                        if (K3)//will three split into a single sheet and a pair of updmin (cur, f[k1 + 1][k2 + 1][k3-1][k4][kx]);                        if (K4)//split four into a single sheet and a stick updmin (cur, f[k1 + 1][k2][k3 + 1][k4-1][kx]);                    if (K4)//Four is split into two pairs updmin (cur, f[k1][k2 + 2][k3][k4-1][kx]);    }}int Main () {int t;    scanf ("%d%d", &t, &cardcnt);    DP ();        while (t--) {Ans = INF;        memset (idcnt, 0, sizeof (idcnt));            for (int i = 1; I <= cardcnt; i++) {int id, color; scanf ("%d%d", &id, &coloR); id = id = = 1? 12:id = = 2? 13:id = = 0?            0:id-2;        idcnt[id]++;        } doshunzi (0, 0, 0, 0);    printf ("%d\n", Ans); } return 0;}

  

luogu2540 Bucket Landlord Enhanced Edition

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.