UCF Practice Local Contest 2018 (practice)Rummy Score (dfs)

dfs,对于每个点数的牌,都有:不出、作为同花出、作为顺子出这三种选择

#include<bits/stdc++.h>
using namespace std;

int a[20],x,anss=0x3f3f3f3f;

void dfs(int k)
{
    if(k>13)
    {
        int sum=0;
        for(int i=1;i<=13;i++)
        {
            sum+=a[i]*i;
        }
        anss=min(anss,sum);
        return;
    }
    if(a[k]==0)
    {
        return dfs(k+1);
    }
    if(a[k]>=3)   //同花
    {
        for(int i=3;i<=a[k];i++)
        {
            a[k]-=i;
            dfs(k);
            a[k]+=i;
        }
    }
    int t=0;
    for(int i=k;i<=13;i++)
    {
        if(a[i]==0)
        break;
        else t++;
        if(t>=3)   //顺子
        {
            for(int j=k;j<=i;j++)
            {
                a[j]--;
            }
            dfs(k);
            for(int j=k;j<=i;j++)
            {
                a[j]++;
            }
        }
    }
    dfs(k+1);   //不出
}

int main()
{
    for(int i=1;i<=7;i++)
    {
        cin>>x;
        a[x]++;
    }
    dfs(1);
    cout<<anss<<endl;
}

原文地址:https://www.cnblogs.com/dyhaohaoxuexi/p/12630864.html

时间: 2024-07-30 14:00:26

UCF Practice Local Contest 2018 (practice)Rummy Score (dfs)的相关文章

poj2965 The Pilots Brothers&#39; refrigerator(直接计算或枚举Enum+dfs)

转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=2965 Description The game "The Pilots Brothers: following the stripy elephant" has a quest where a player needs to open a refrigerator. There are 16 handles

HDU1010 Tempter of the Bone(小狗是否能逃生----DFS)

Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggi

hdu1428 记忆化搜索(BFS预处理最短路径和+DP+DFS)

题意:有一块 n * n 大小的方形区域,要从左上角 (1,1)走到右下角(n,n),每个格子都有通过所需的时间,并且每次所走的下一格到终点的最短时间必须比当前格子走到重点的最短时间短,问一共有多少种走法. 这道题还是很明显的 DP 的,而且鉴于走到相邻格点可以上下左右走,所以我很快就锁定了记忆化搜索这种 DP 方式,但是事实上我的思路大方向的确没有错误,但是我仍然没有很好地挖掘题目的信息.我的想法是,某点到结尾的最短距离我可以转化成到起始点的最短距离,这样我就能从开头的点开始遍历,并且在遍历的

UCF “Practice” Local Contest — Aug 25, 2018 Rummy Score

数据范围很小,搜索即可 #include<bits/stdc++.h> #define sc(n) scanf("%d",&n) #define ll long long #define db double #define P pair<int,int> using namespace std; int a[14], ans, v[14]; void dfs(int k, int tot, int kind, int cnt, int tott, int

UCF “Practice” Local Contest — Aug 25, 2018 Call Me Maybe

根据题意模拟 #include <bits/stdc++.h> #define ull unsigned long long #define P pair<int, int> #define sc(n) scanf("%d", &n) using namespace std; const int p = 131; int n, m, tot, w[100005]; vector<P> ve[100005]; map<ull, int&g

UCF “Practice” Local Contest — Aug 25, 2018 Boots Exchange 水题

#include <bits/stdc++.h> using namespace std; int n; set <int> a; map <int,int> cnt; int main() { cin >> n; int ans = 0; for (int i = 1; i <= n; ++i) { int x; cin >> x; a.insert(x); ++cnt[x]; } for (int i = 1; i <= n; +

HDU 5179 beautiful number (数位dp / 暴力打表 / dfs)

beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 801    Accepted Submission(s): 518 Problem Description Let A=∑ni=1ai?10n?i(1≤ai≤9)(n is the number of A's digits). We call A as "

(UVA)1585 --Score(得分)

时间限制:3000MS 64位IO格式:%lld&%llu 描述 有一个客观的测试结果,如"OOXXOXXOOO",一个"O"表示一个问题的正确答案,一个"X"表示一个错误的答案.这个测试的每个问题的分数是由它自己计算的,例如,第10个问题的得分是3,它是由它自己和它的前两个连续的O得到的.因此,"OOXXOXXOOO"的分数是由"1 + 2 + 0 + 0 + 1 + 0 + 0 + 1 + 2 + 3&q

2018.1.27 扇贝新闻精选(5/10)

Health Officials: More Birth Defects in US Areas With Zika 卫生部负责人(表示):在美国地区出现更多与寨卡病毒相关的先天缺陷 (2016年1月16日,在巴西累西腓的 Fiocruz 基金会,一只携带寨卡病毒的埃及伊蚊通过显微镜被拍摄) CHICAGO - 芝加哥(来讯)-- ★ Health Officials:看到词典上的解释是"卫生官员"或者"健康官员",确实有这一说法,结合下文提到的美国疾病控制与预防中