QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#1245#780455#9549. The MagicianImakfImakfSuccess!2024-11-25 11:04:282024-11-25 11:04:29

詳細信息

Extra Test:

Wrong Answer
time: 1ms
memory: 6160kb

input:

3
35
4C 3C 2C AC TH 9H 8H 7H 6H 5H 4H 3H 2H AH TD 9D 8D 7D 6D 5D 4D 3D 2D AD JS TS 9S 8S 7S 6S 5S 4S 3S 2S AS
0 0 0 0 1 1
41
9C 8C 7C 6C 5C 4C 3C 2C AC 9H 8H 7H 6H 5H 4H 3H 2H AH TD 9D 8D 7D 6D 5D 4D 3D 2D AD KS QS JS TS 9S 8S 7S 6S 5S 4S 3S 2S AS
0 1 1 1 0 0
28
AC 4H 3H 2H AH TD 9D 8D 7D 6D 5D 4D 3...

output:

6
8
5

result:

wrong answer 1st lines differ - expected: '7', found: '6'

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#780455#9549. The MagicianImakfWA 5ms6356kbC++2319.8kb2024-11-25 11:03:452024-11-25 11:15:41

answer

// https://codeforces.com/gym/105540/submission/292446489
#include<bits/stdc++.h>
using namespace std;
int f[10][10][10][10][2][2][2][2][2][2];
int a[5];
int dfs(int a1,int a2,int a3,int a4,int x1,int x2,int x3,int x4,int x5,int x6)
{
    //cout << a1 << " " << a2 << " " << a3 << " " << a4 << '\n';
    if((x1||x2||x3||x4||x5||x6)==0)
    {
        f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=a1/5+a2/5+a3/5+a4/5;
        return a1/5+a2/5+a3/5+a4/5;
    }
    if(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]!=-1)
    {
        return f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6];
    }
    f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=0;
    if(x1)
    {
        if(a2>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+1,a2-1,a3,a4,0,x2,x3,x4,x5,x6));
        }
        if(a3>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+1,a2,a3-1,a4,0,x2,x3,x4,x5,x6));
        }
        if(a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+1,a2,a3,a4-1,0,x2,x3,x4,x5,x6));
        }
        if(a2>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+2,a2-2,a3,a4,0,x2,x3,x4,x5,x6));
        }
        if(a3>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+2,a2,a3-2,a4,0,x2,x3,x4,x5,x6));
        }
        if(a4>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+2,a2,a3,a4-2,0,x2,x3,x4,x5,x6));
        }
        if(a2>=3)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+3,a2-3,a3,a4,0,x2,x3,x4,x5,x6));
        }
        if(a3>=3)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+3,a2,a3-3,a4,0,x2,x3,x4,x5,x6));
        }
        if(a4>=3)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+3,a2,a3,a4-3,0,x2,x3,x4,x5,x6));
        }
        if(a2>=1&&a3>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+2,a2-1,a3-1,a4,0,x2,x3,x4,x5,x6));
        }
        if(a2>=1&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+2,a2-1,a3,a4-1,0,x2,x3,x4,x5,x6));
        }
        if(a3>=1&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+2,a2,a3-1,a4-1,0,x2,x3,x4,x5,x6));
        }
        if(a2>=1&&a3>=1&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+3,a2-1,a3-1,a4-1,0,x2,x3,x4,x5,x6));
        }
        if(a2>=2&&a3>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+3,a2-2,a3-1,a4,0,x2,x3,x4,x5,x6));
        }
        if(a2>=1&&a3>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+3,a2-1,a3-2,a4,0,x2,x3,x4,x5,x6));
        }
        if(a2>=2&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+3,a2-2,a3,a4-1,0,x2,x3,x4,x5,x6));
        }
        if(a2>=1&&a4>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+3,a2-1,a3,a4-2,0,x2,x3,x4,x5,x6));
        }
        if(a3>=2&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+3,a2,a3-2,a4-1,0,x2,x3,x4,x5,x6));
        }
        if(a3>=1&&a4>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+3,a2,a3-1,a4-2,0,x2,x3,x4,x5,x6));
        }
    }
    if(x2)
    {
        if(a1>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2+1,a3,a4,x1,0,x3,x4,x5,x6));
        }
        if(a3>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2+1,a3-1,a4,x1,0,x3,x4,x5,x6));
        }
        if(a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2+1,a3,a4-1,x1,0,x3,x4,x5,x6));
        }
        if(a1>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-2,a2+2,a3,a4,x1,0,x3,x4,x5,x6));
        }
        if(a3>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2+2,a3-2,a4,x1,0,x3,x4,x5,x6));
        }
        if(a4>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2+2,a3,a4-2,x1,0,x3,x4,x5,x6));
        }
        if(a1>=3)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-3,a2+3,a3,a4,x1,0,x3,x4,x5,x6));
        }
        if(a3>=3)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2+3,a3-3,a4,x1,0,x3,x4,x5,x6));
        }
        if(a4>=3)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2+3,a3,a4-3,x1,0,x3,x4,x5,x6));
        }
        if(a1>=1&&a3>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2+2,a3-1,a4,x1,0,x3,x4,x5,x6));
        }
        if(a1>=1&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2+2,a3,a4-1,x1,0,x3,x4,x5,x6));
        }
        if(a3>=1&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2+2,a3-1,a4-1,x1,0,x3,x4,x5,x6));
        }
        if(a1>=1&&a3>=1&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2+3,a3-1,a4-1,x1,0,x3,x4,x5,x6));
        }
        if(a1>=2&&a3>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-2,a2+3,a3-1,a4,x1,0,x3,x4,x5,x6));
        }
        if(a1>=1&&a3>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2+3,a3-2,a4,x1,0,x3,x4,x5,x6));
        }
        if(a1>=2&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-2,a2+3,a3,a4-1,x1,0,x3,x4,x5,x6));
        }
        if(a1>=1&&a4>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2+3,a3,a4-2,x1,0,x3,x4,x5,x6));
        }
        if(a3>=2&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2+3,a3-2,a4-1,x1,0,x3,x4,x5,x6));
        }
        if(a3>=1&&a4>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2+3,a3-1,a4-2,x1,0,x3,x4,x5,x6));
        }
    }
    if(x3)
    {
        if(a1>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2,a3+1,a4,x1,x2,0,x4,x5,x6));
        }
        if(a2>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-1,a3+1,a4,x1,x2,0,x4,x5,x6));
        }
        if(a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2,a3+1,a4-1,x1,x2,0,x4,x5,x6));
        }
        if(a1>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-2,a2,a3+2,a4,x1,x2,0,x4,x5,x6));
        }
        if(a2>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-2,a3+2,a4,x1,x2,0,x4,x5,x6));
        }
        if(a4>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2,a3+2,a4-2,x1,x2,0,x4,x5,x6));
        }
        if(a1>=3)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-3,a2,a3+3,a4,x1,x2,0,x4,x5,x6));
        }
        if(a2>=3)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-3,a3+3,a4,x1,x2,0,x4,x5,x6));
        }
        if(a4>=3)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2,a3+3,a4-3,x1,x2,0,x4,x5,x6));
        }
        if(a1>=1&&a2>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2-1,a3+2,a4,x1,x2,0,x4,x5,x6));
        }
        if(a1>=1&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2,a3+2,a4-1,x1,x2,0,x4,x5,x6));
        }
        if(a2>=1&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-1,a3+2,a4-1,x1,x2,0,x4,x5,x6));
        }
        if(a1>=1&&a2>=1&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2-1,a3+3,a4-1,x1,x2,0,x4,x5,x6));
        }
        if(a1>=2&&a2>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-2,a2-1,a3+3,a4,x1,x2,0,x4,x5,x6));
        }
        if(a1>=1&&a2>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2-2,a3+3,a4,x1,x2,0,x4,x5,x6));
        }
        if(a1>=2&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-2,a2,a3+3,a4-1,x1,x2,0,x4,x5,x6));
        }
        if(a1>=1&&a4>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2,a3+3,a4-2,x1,x2,0,x4,x5,x6));
        }
        if(a2>=2&&a4>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-2,a3+3,a4-1,x1,x2,0,x4,x5,x6));
        }
        if(a2>=1&&a4>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-1,a3+3,a4-2,x1,x2,0,x4,x5,x6));
        }
    }
    if(x4)
    {
        if(a1>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2,a3,a4+1,x1,x2,x3,0,x5,x6));
        }
        if(a2>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-1,a3,a4+1,x1,x2,x3,0,x5,x6));
        }
        if(a3>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2,a3-1,a4+1,x1,x2,x3,0,x5,x6));
        }
        if(a1>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-2,a2,a3,a4+2,x1,x2,x3,0,x5,x6));
        }
        if(a2>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-2,a3,a4+2,x1,x2,x3,0,x5,x6));
        }
        if(a3>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2,a3-2,a4+2,x1,x2,x3,0,x5,x6));
        }
        if(a1>=3)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-3,a2,a3,a4+3,x1,x2,x3,0,x5,x6));
        }
        if(a2>=3)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-3,a3,a4+3,x1,x2,x3,0,x5,x6));
        }
        if(a3>=3)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2,a3-3,a4+3,x1,x2,x3,0,x5,x6));
        }
        if(a1>=1&&a2>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2-1,a3,a4+2,x1,x2,x3,0,x5,x6));
        }
        if(a1>=1&&a3>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2,a3-1,a4+2,x1,x2,x3,0,x5,x6));
        }
        if(a2>=1&&a3>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-1,a3-1,a4+2,x1,x2,x3,0,x5,x6));
        }
        if(a1>=1&&a2>=1&&a3>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2-1,a3-1,a4+3,x1,x2,x3,0,x5,x6));
        }
        if(a1>=2&&a2>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-2,a2-1,a3,a4+3,x1,x2,x3,0,x5,x6));
        }
        if(a1>=1&&a2>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2-2,a3,a4+3,x1,x2,x3,0,x5,x6));
        }
        if(a1>=2&&a3>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-2,a2,a3-1,a4+3,x1,x2,x3,0,x5,x6));
        }
        if(a1>=1&&a3>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2,a3-2,a4+3,x1,x2,x3,0,x5,x6));
        }
        if(a2>=2&&a3>=1)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-2,a3-1,a4+3,x1,x2,x3,0,x5,x6));
        }
        if(a2>=1&&a3>=2)
        {
            f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-1,a3-2,a4+3,x1,x2,x3,0,x5,x6));
        }
    }
    if(x5)
    {
        if(a1)
        {
            if(a2)
            {
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+1,a2-1,a3,a4,x1,x2,x3,x4,0,x6));
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2+1,a3,a4,x1,x2,x3,x4,0,x6));
            }
            if(a3)
            {
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+1,a2,a3-1,a4,x1,x2,x3,x4,0,x6));
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2,a3+1,a4,x1,x2,x3,x4,0,x6));
            }
            if(a4)
            {
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+1,a2,a3,a4-1,x1,x2,x3,x4,0,x6));
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2,a3,a4+1,x1,x2,x3,x4,0,x6));
            }
        }
        if(a2)
        {
            if(a3)
            {
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2+1,a3-1,a4,x1,x2,x3,x4,0,x6));
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-1,a3+1,a4,x1,x2,x3,x4,0,x6));
            }
            if(a4)
            {
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2+1,a3,a4-1,x1,x2,x3,x4,0,x6));
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-1,a3,a4+1,x1,x2,x3,x4,0,x6));
            }
        }
        if(a3)
        {
            if(a4)
            {
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2,a3+1,a4-1,x1,x2,x3,x4,0,x6));
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2,a3-1,a4+1,x1,x2,x3,x4,0,x6));
            }
        }
    }
    if(x6)
    {
        if(a1)
        {
            if(a2)
            {
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+1,a2-1,a3,a4,x1,x2,x3,x4,x5,0));
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2+1,a3,a4,x1,x2,x3,x4,x5,0));
            }
            if(a3)
            {
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+1,a2,a3-1,a4,x1,x2,x3,x4,x5,0));
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2,a3+1,a4,x1,x2,x3,x4,x5,0));
            }
            if(a4)
            {
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1+1,a2,a3,a4-1,x1,x2,x3,x4,x5,0));
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1-1,a2,a3,a4+1,x1,x2,x3,x4,x5,0));
            }
        }
        if(a2)
        {
            if(a3)
            {
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2+1,a3-1,a4,x1,x2,x3,x4,x5,0));
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-1,a3+1,a4,x1,x2,x3,x4,x5,0));
            }
            if(a4)
            {
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2+1,a3,a4-1,x1,x2,x3,x4,x5,0));
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2-1,a3,a4+1,x1,x2,x3,x4,x5,0));
            }
        }
        if(a3)
        {
            if(a4)
            {
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2,a3+1,a4-1,x1,x2,x3,x4,x5,0));
                f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6]=max(f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6],dfs(a1,a2,a3-1,a4+1,x1,x2,x3,x4,x5,0));
            }
        }
    }
    return f[a1][a2][a3][a4][x1][x2][x3][x4][x5][x6];
}
void solve()
{
    int x1,x2,x3,x4,x5,x6;
    a[1]=a[2]=a[3]=a[4]=0;
    int n;
    string s;
    cin >> n;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        cin >> s;
        if(s[1]=='D')
        {
            a[1]++;
        }
        else if(s[1]=='C')
        {
            a[2]++;
        }
        else if(s[1]=='H')
        {
            a[3]++;
        }
        else if(s[1]=='S')
        {
            a[4]++;
        }
    }
    cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6;
    for(int i=1;i<=4;i++)
    {
        ans+=a[i]/5;
        a[i]=a[i]%5;
        //cout << i << " " << a[i] << '\n';
    }
    cout << ans + dfs(a[1],a[2],a[3],a[4],x1,x2,x3,x4,x5,x6) << '\n';
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    memset(f,-1,sizeof(f));
    while (T -- )
    {
        solve();
    }
    return 0;
}