loj 6434 "PKUSC2018" main fighting ground

serious

Landlords do most of the series title (?)

Apparently the idea is pathetic burst search card, and then went to find out whether there is a legitimate licensing program. Because the total number of programs only a few hundred million species, so you can directly enumerate each program

Then check the optimization process. First of all can be found even on the sub-three-card straight Sanshun can be split into a number of single-brand, the aircraft can be split into a number three with a two or three zones, so only we only consider single card, the three with one, three with two, four with two. If you only consider a single card, then it must be both cards were ranked after a good sequence, and the poor a card must strictly correspond to the location of users is less than the brand, so this can be from large to small enumeration card size, and then see whether the poor each brand has a bigger card users can be coupled pairs, complexity is \ (O (14) \) , that is, the number of kinds of cards

Then consider the remaining three \ (x \) with \ (y \) . We put all \ (x \) with \ (y \) as the first selected \ (x \) , and then choose \ (y \ ) . so you can make two people to play only three or four of the same cards, and record the number of the next three or four cards of the cards, and then some behind San card processing corresponds with, because there is no limit these scattered cards the size of the relationship, so this is actually \ (x \) with \ (y \) role is to put some big points lead to good enough for the brand to disappear. a set of three cards can pair with a single card or a set of , so the best way to four cards can be with twin single card, so we can enumerate a few dozen pairs, noting that without the enumeration of various sub-game, because we want to try to eliminate the poor large cards each selection is poor biggest pair disappear; the same greedy consideration, we use the smallest pair paired friends, apparently also some of the best of the last remaining four cards or three cards did not bring something (. with a \ (a \) group of three cards, \ (b \) rent four cards), as enumerated in front of the sub, then the remaining three cards we force it with a single card, so that you can also choose the most \ (a + 2b \) single card pair, the remaining cards Only one correspondence with a single card to check. Specifically, if there is a single card check process \ (c \) cards are not paired, so if they meet \ (c \ Le A +. 2B \) , then this program is legitimate, because two people will have \ (c \)Cards are not paired well, then that \ (c \) cards are three cards or four cards put on the line. Complexity \ (O (can live) \)

#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
#define db double

using namespace std;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
char cc[20];
int mpp[127];
void inii()
{
    mpp['4']=0;
    mpp['5']=1;
    mpp['6']=2;
    mpp['7']=3;
    mpp['8']=4;
    mpp['9']=5;
    mpp['T']=6;
    mpp['J']=7;
    mpp['Q']=8;
    mpp['K']=9;
    mpp['A']=10;
    mpp['2']=11;
    mpp['w']=12;
    mpp['W']=13;
}
int lm[14]={4,4,4,4,4,4,4,4,4,4,4,4,1,1};
int ans,ntz[14],karen[14];
bool ck(int pk,int ls,int c1,int c2)
{
    int sm=0;
    for(int i=13;~i;--i)
    {
        sm-=karen[i];
        sm=max(sm,0)+ntz[i];
    }
    if(sm<=c1+c2*2) return 1;
    int m1,m2;
    bool ok=0;
    for(;pk>=3;--pk)
    {
        m1=ls;
        while(m1<=13&&karen[m1]<pk) ++m1;
        while(m1<=13)
        {
            m2=m1+1;
            while(m2<=13&&ntz[m2]<pk) ++m2;
            if(m2>13) break;
            while(m2<=13)
            {
                karen[m1]-=pk,ntz[m2]-=pk;
                ok=ck(pk,m1+1,c1+(pk==3),c2+(pk==4));
                karen[m1]+=pk,ntz[m2]+=pk;
                if(ok) return 1;
                ++m2;
                while(m2<=13&&ntz[m2]<pk) ++m2;
            }
            ++m1;
            while(m1<=13&&karen[m1]<pk) ++m1;
        }
        ls=0;
    }
    if(!c1) return 0;
    m1=13,m2=0;
    while((~m1)&&karen[m1]<pk) --m1;
    while(m2<=13&&ntz[m2]<pk) ++m2;
    if(m1<0||m2>13) return 0;
    karen[m1]-=pk,ntz[m2]-=pk;
    ok=ck(pk,ls,c1-1,c2);
    karen[m1]+=pk,ntz[m2]+=pk;
    return ok;
}
void dfs(int o,int nm)
{
    if(nm==17)
    {
        if(ck(4,0,0,0)) ++ans;
        return;
    }
    if(o>13) return;
    for(int i=0;i<=lm[o]&&nm+i<=17;++i)
    {
        karen[o]=i;
        dfs(o+1,nm+i);
    }
    karen[o]=0;
}

int main()
{
    inii();
    scanf("%s",cc+1);
    for(int i=1;i<=17;++i) ++ntz[mpp[cc[i]]],--lm[mpp[cc[i]]];
    dfs(0,0);
    printf("%d\n",ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/smyjr/p/12098506.html