Problem: treasure card a lot (DP & Card Chang)

topic

Portal

Thinking

This question is the main subject of the bad state of want and not well understood

If you and I had no contact with the same Mahjong

We first performed the entire mahjong hash processing

Defined \ (dp_ {i, j, k, l, m, n} \) front the i cards, the number of taping and face a total of j, the number of birds have to k, of \ (i-2 \) species number of cards is l, of \ (i-1 \) number of card types is m, the number of kinds of cards is n i

To note that the value of the DP is not i-2 ~ i into consideration the three cards

You can write transfer

\ (\ begin {cases} dp_ {i, j + 1, k, l + 1, m + 1, n + 1} (\ mbox { straight}) \\ dp_ {i, j + 1, k, l , m, n + 3} (pung) \\ dp_ {i, j + 1, k, l, m, n + 4} ( first bar) \\ dp_ {i, j, k + 1, l, m , n + 2} (The birds) \ Cases} End {\) = \ (dp_ {I, J, K, L, m, n-} \)

Direct transfer place, because we \ (dp \) is not considered i-2 ~ i kind of chess

In another case

\(dp_{i+1,j,k,m,n,0}=dp_{i,j,k,m,n,l}*C_{t_{i}}^l*qkpow(bp_i,l)\)

Wherein \ (t_i \) represents the remaining number of the i-chess, \ (bp_i = \ Cases the begin {2} [Po is the i-th number of cards] \\ 1 [i-th-card is not] \ end {cases} \)

When the significance of the equation would not consider the i chess, the current \ (dp \) state back transfer, is also very good understanding of

Do not forget to add the last contribution statistics about statistics when three last chess

Then talk about optimization

The current state is 0 can skip

Proof: The last state must be a product of formula, wherein when a is 0, 0 is directly entire

Can not be considered thick stick

Proof: \ (^ 3 = 4 C_4 and C_4 ^ 4 = 1 \) means that even if this card is a treasure card is not worthwhile

But this does not mean that the condition will become cycle, we just continue more than a few state

In fact constant level decreases

But you can make 50 points helicopter from 100 points

This question is really good road (cancer) title

The importance of constant glance

Code

#pragma GCC optimize(2)
#include<iostream>
#include<cstring>
#include<climits>
#include<queue>
using namespace std;
int T;
priority_queue<int> q;
long long ans;
long long tmp;
int num_pow[3][5];
long long dp[35][5][2][5][5][5];
int sz[35]={0,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0};
int gs[14]={0,1,9,10,18,19,27,28,29,30,31,32,33,34};
int t[35];
int bp[35];
int c[5][5]=
{
{1,0,0,0,0},
{1,1,0,0,0},
{1,2,1,0,0},
{1,3,3,1,0},
{1,4,6,4,1}
};
string a;
int solve_hash(string a)
{
    if(a[1]=='m')
        return a[0]-'0';
    if(a[1]=='p')
        return a[0]-'0'+9;
    if(a[1]=='s')
        return a[0]-'0'+18;
    if(a[0]=='E')
        return 28;
    if(a[0]=='S')
        return 29;
    if(a[0]=='W')
        return 30;
    if(a[0]=='N')
        return 31;
    if(a[0]=='Z')
        return 32;
    if(a[0]=='B')
        return 33;
    if(a[0]=='F')
        return 34;
}
void init()
{
    while(!q.empty())
        q.pop();
    memset(dp,0,sizeof(dp));
    dp[1][0][0][0][0][0]=1;
    ans=0;
    for(int i=1;i<=34;i++)
    {
        bp[i]=1;
        t[i]=4;
    }
}
int qkpow(int a,int b)
{
    if(num_pow[a][b])
        return num_pow[a][b];
    if(b==0)
        return 1;
    if(b==1)
        return a;
    long long t=qkpow(a,b/2);
    t=(t*t);
    if(b%2==1)
        t*=a;
    num_pow[a][b]=t;
    return t;
}
void c_in()
{
    init();
    while(1)
    {
        cin>>a;
        if(a[0]=='0')
            break;
        t[solve_hash(a)]--;
    }
    while(1)
    {
        cin>>a;
        if(a[0]=='0')
            break;
        bp[solve_hash(a)]=2;
    }
    for(int i=1;i<=13;i++)
    {
        tmp=1;
        for(int j=1;j<=13;j++)
        {
            if(i==j)
            {
                if(t[gs[i]]<2)
                    tmp=0;
                else
                    tmp=tmp*c[t[gs[i]]][2]*qkpow(bp[gs[i]],2);
            }
            else
            {
                if(!t[gs[j]])
                    tmp=0;
                else
                    tmp=tmp*c[t[gs[j]]][1]*qkpow(bp[gs[j]],1);
            }
        }
        ans=max(ans,tmp*13);
    }
    for(int i=1;i<=34;i++)
        if(t[i]>=2)
            q.push(c[t[i]][2]*qkpow(bp[i],2));
    if(q.size()>=7)
    {
        tmp=1;
        for(int i=1;i<=7;i++)
        {
            tmp=tmp*q.top();
            q.pop();
        }
        ans=max(ans,tmp*7);
    }
    for(int i=1;i<=34;i++)
    {
        for(int j=0;j<=4;j++)
        {
            for(int k=0;k<=1;k++)
            {
                for(int l=0;l<=4;l++)
                {
                    for(int m=0;m<=4;m++)
                    {
                        for(int n=0;n<=4;n++)
                        {
                            long long now=dp[i][j][k][l][m][n];
                            if(!now)
                                continue;   
                            if(k==0&&t[i]-n>=2)
                                dp[i][j][k+1][l][m][n+2]=max(dp[i][j][k+1][l][m][n+2],now);
                            if(t[i]-n>=3&&j<4)
                                dp[i][j+1][k][l][m][n+3]=max(dp[i][j+1][k][l][m][n+3],now);
                            if(sz[i]&&t[i-2]-l>=1&&t[i-1]-m>=1&&t[i]-n>=1&&j<4)
                                dp[i][j+1][k][l+1][m+1][n+1]=max(dp[i][j+1][k][l+1][m+1][n+1],now);
                            if(i<34)
                                dp[i+1][j][k][m][n][0]=max(dp[i+1][j][k][m][n][0],now*(i>2?c[t[i-2]][l]:1)*qkpow(i>2?bp[i-2]:1,l));
                            if(i==34&&j==4&&k==1)
                                ans=max(ans,now*c[t[i-2]][l]*qkpow(bp[i-2],l)*c[t[i-1]][m]*qkpow(bp[i-1],m)*c[t[i]][n]*qkpow(bp[i],n));
                        }
                    }
                }
            }
        }
    }
    cout<<ans<<'\n';
}
int main()
{ 
    ios::sync_with_stdio(false);
    cin>>T;
    for(int i=1;i<=T;i++)
        c_in();
    return 0;
}

Yes that is six-dimensional

Guess you like

Origin www.cnblogs.com/loney-s/p/12041057.html