单纯的暴搜似乎还是很好写的,然而过不了。出完顺子之后答案是可以dp出来的,于是大力搜然后大力dp就好了。

  dp时强行讨论完了几乎所有拆牌情况,理性愉悦一发。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int T,n,cnt[],f[][][][][],ans;//1:2 2~12:3~K 13:A 14 15:ghost
void dfs(int k,int step);
void threestraight(int k,int step)
{
for (int i=;i<=;i++)
if (cnt[i]>=&&cnt[i+]>=)
{
cnt[i]-=,cnt[i+]-=;dfs(k-,step+);
int t=i+;while (cnt[t+]>=) t++,cnt[t]-=,dfs(k-(t-i+)*,step+);
while (t>=i) cnt[t]+=,t--;
}
}
void twostraight(int k,int step)
{
for (int i=;i<=;i++)
if (cnt[i]>=&&cnt[i+]>=&&cnt[i+]>=)
{
cnt[i]-=,cnt[i+]-=,cnt[i+]-=;dfs(k-,step+);
int t=i+;while (cnt[t+]>=) t++,cnt[t]-=,dfs(k-((t-i+)<<),step+);
while (t>=i) cnt[t]+=,t--;
}
}
void onestraight(int k,int step)
{
for (int i=;i<=;i++)
if (cnt[i]&&cnt[i+]&&cnt[i+]&&cnt[i+]&&cnt[i+])
{
cnt[i]--,cnt[i+]--,cnt[i+]--,cnt[i+]--,cnt[i+]--;dfs(k-,step+);
int t=i+;while (t<&&cnt[t+]) t++,cnt[t]--,dfs(k-(t-i+),step+);
while (t>=i) cnt[t]++,t--;
}
}
void dfs(int k,int step)
{
int t[]={};
for (int i=;i<=;i++) if (cnt[i]) t[cnt[i]]++;
t[]=cnt[]+cnt[];
ans=min(ans,step+f[t[]][t[]][t[]][t[]][t[]]);
if (step+(k>)>=ans) return;
if (k==) return;
threestraight(k,step);
twostraight(k,step);
onestraight(k,step);
}
inline void update(int &x,int y){x=min(x,y);}
void dp()
{
memset(f,,sizeof(f));
f[][][][][]=;
for (int i=;i<=n;i++)
for (int x=;x<=i;x++)
for (int y=;y*<=i-x;y++)
for (int z=;z*<=i-x-y*;z++)
for (int t=;t*<=i-x-y*-z*;t++)
for (int g=;g<=min(,i-x-y*-z*-t*);g++)
{
if (x) update(f[x][y][z][t][g],f[x-][y][z][t][g]+);
if (y) update(f[x][y][z][t][g],f[x][y-][z][t][g]+);
if (y) update(f[x][y][z][t][g],f[x+][y-][z][t][g]+);
if (z) update(f[x][y][z][t][g],f[x][y][z-][t][g]+);
if (z) update(f[x][y][z][t][g],f[x][y+][z-][t][g]+);
if (z) update(f[x][y][z][t][g],f[x+][y][z-][t][g]+);
if (t) update(f[x][y][z][t][g],f[x][y][z][t-][g]+);
if (t) update(f[x][y][z][t][g],f[x][y][z+][t-][g]+);
if (t) update(f[x][y][z][t][g],f[x][y+][z][t-][g]+);
if (t) update(f[x][y][z][t][g],f[x+][y][z][t-][g]+);
if (g) update(f[x][y][z][t][g],f[x][y][z][t][g-]+);
if (g==) update(f[x][y][z][t][g],f[x][y][z][t][g-]+);
//part 1 only one
if (z&&x) update(f[x][y][z][t][g],f[x-][y][z-][t][g]+);
if (z&&y) update(f[x][y][z][t][g],f[x+][y-][z-][t][g]+);
if (z>=) update(f[x][y][z][t][g],f[x][y+][z-][t][g]+);
if (z&&g) update(f[x][y][z][t][g],f[x][y][z-][t][g-]+);
if (t&&y) update(f[x][y][z][t][g],f[x+][y-][z][t-][g]+);
if (t>=) update(f[x][y][z][t][g],f[x+][y][z+][t-][g]+);
if (t&&g) update(f[x][y][z][t][g],f[x][y][z][t-][g-]+);
//part 2 three with one
if (z&&y) update(f[x][y][z][t][g],f[x][y-][z-][t][g]+);
if (z>=) update(f[x][y][z][t][g],f[x+][y][z-][t][g]+);
if (z&&t) update(f[x][y][z][t][g],f[x][y+][z-][t-][g]+);
if (t&&y) update(f[x][y][z][t][g],f[x+][y-][z][t-][g]+);
if (t&&z) update(f[x][y][z][t][g],f[x+][t][z-][t-][g]+);
if (t>=) update(f[x][t][z][t][g],f[x+][y+][z][t-][g]+);
//part 3 three with two
if (t)
{
if (x>=) update(f[x][y][z][t][g],f[x-][y][z][t-][g]+);
if (x&&g) update(f[x][y][z][t][g],f[x-][y][z][t-][g-]+);
if (y) update(f[x][y][z][t][g],f[x][y-][z][t-][g]+);
if (y>=) update(f[x][y][z][t][g],f[x+][y-][z][t-][g]+);
if (y&&g) update(f[x][y][z][t][g],f[x+][y-][z][t-][g-]+);
if (z) update(f[x][y][z][t][g],f[x+][y][z-][t-][g]+);
if (z&&x) update(f[x][y][z][t][g],f[x-][y+][z-][t-][g]+);
if (z&&y) update(f[x][y][z][t][g],f[x+][y][z-][t-][g]+);
if (z>=) update(f[x][y][z][t][g],f[x][y+][z-][t-][g]+);
if (z&&g) update(f[x][y][z][t][g],f[x][y+][z-][t-][g-]+);
if (t>=) update(f[x][y][z][t][g],f[x][y+][z][t-][g]+);
if (t>=) update(f[x][y][z][t][g],f[x][y][z+][t-][g]+);
if (t>=&&x) update(f[x][y][z][t][g],f[x-][y][z+][t-][g]+);
if (t>=&&y) update(f[x][y][z][t][g],f[x+][y-][z+][t-][g]+);
if (t>=&&z) update(f[x][y][z][t][g],f[x][y+][z][t-][g]+);
if (t>=&&g) update(f[x][y][z][t][g],f[x][y][z+][t-][g-]+);
if (g>=) update(f[x][y][z][t][g],f[x][y][z][t-][g-]+);
//part 4 four with one
if (y>=) update(f[x][y][z][t][g],f[x][y-][z][t-][g]+);
if (z>=) update(f[x][y][z][t][g],f[x+][y][z-][t-][g]+);
if (y&&z) update(f[x][y][z][t][g],f[x+][y][z-][t-][g]+);
if (t>=&&z) update(f[x][y][z][t][g],f[x+][y+][z-][t-][g]+);
if (t>=) update(f[x][y][z][t][g],f[x][y][z][t-][g]+);
if (t>=) update(f[x][y][z][t][g],f[x][y+][z][t-][g]+);
//part 5 four with two
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("2540.in","r",stdin);
freopen("2540.out","w",stdout);
const char LL[]="%I64d\n";
#else
const char LL[]="%lld\n";
#endif
T=read(),n=read();
dp();
while (T--)
{
ans=n;memset(cnt,,sizeof(cnt));
for (int i=;i<=n;i++)
{
int x=read(),y=read();
if (x==) cnt[y+]++;
else if (x==) cnt[]++;
else if (x==) cnt[]++;
else cnt[x-]++;
}
dfs(n,);
cout<<ans<<endl;
}
return ;
}

Luogu2540 斗地主增强版(搜索+动态规划)的更多相关文章

  1. [Luogu2540][NOIP2016]斗地主增强版(搜索+DP)

    增强版就是原版中两鬼不算对子的版本. 先爆搜出完所有对子,剩下的牌DP处理. 考虑每个数码的拆牌情况,最多可能被拆成5种情况:1+1+1+1,1+1+2,1+3,2+2,4.故DP状态数最多为5^13 ...

  2. luogu2540 斗地主增强版

    题目大意 给你一副手牌,没有飞机带翅膀,按斗地主的规则,求将所有牌打出的最少次数. 题解 先不考虑顺子 我们已经知道花色对牌没有影响,那么如果不考虑顺子,每个牌具体是什么数字我们也用不着知道,我们关心 ...

  3. Luogu 2540 斗地主增强版(搜索,动态规划)

    Luogu 2540 斗地主增强版(搜索,动态规划) Description 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游 ...

  4. P2540 斗地主增强版

    P2540斗地主增强版 参考大佬题解 思路:顺子暴力搜,剩下的牌我不会贪心所以用记忆化搜索(或者dp): 注意:双王不能当对,二不算顺子 代码 #include <cstdio> #inc ...

  5. 洛谷 题解 P2540 【斗地主增强版】

    [分析] 暴力搜顺子,贪心出散牌 为什么顺子要暴力? 玩过斗地主的都知道,并不是出越长的顺子越好,如果你有一组手牌,3,4,5,6,7,6,7,8,9,10,你一下把最长的出了去,你会单两张牌,不如出 ...

  6. 【NOIP2015】斗地主 D1 T3 及 增强版 (送命题)

    恶心送命模拟题 暴搜顺子,DP预处理剩下的. 由于官方数据太水,很多情况没有讨论的都能过普通版本,想要测试自己代码正确性的同学们可以交交这道题,有很多dalao给出了hack数据 : Luogu P2 ...

  7. 《zw版·delphi与halcon系列原创教程》zw版_THOperatorSetX控件函数列表 v11中文增强版

    <zw版·delphi与halcon系列原创教程>zw版_THOperatorSetX控件函数列表v11中文增强版 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就 ...

  8. 微慕WordPress小程序增强版

    2017年1月9日,张小龙在2017微信公开课Pro上发布的微信小程序正式上线.在过去的2年多的时间里,微信小程序领头,各大互联网平台也不甘落后,陆续推出自己的小程序.2018年7月4日,百度智能小程 ...

  9. 将表里的数据批量生成INSERT语句的存储过程 增强版

    将表里的数据批量生成INSERT语句的存储过程 增强版 有时候,我们需要将某个表里的数据全部或者根据查询条件导出来,迁移到另一个相同结构的库中 目前SQL Server里面是没有相关的工具根据查询条件 ...

随机推荐

  1. 成都Uber优步司机奖励政策(3月28日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  2. 3329: Xorequ

    3329: Xorequ https://www.lydsy.com/JudgeOnline/problem.php?id=3329 分析: 因为a+b = a^b + ((a&b)<& ...

  3. LeetCode: 53. Maximum Subarray(Easy)

    1. 原题链接 https://leetcode.com/problems/maximum-subarray/discuss/ 2. 题目要求 给定一个整型数组,返回其子串之和的最大值 例如,[-2, ...

  4. 适配chrome65最新selenium-chromedriver

    网盘地址:https://pan.baidu.com/s/1BmdwRgD96IL32-3FTFxPSg 密码: 2vg6

  5. Micro:bit 硬件架构介绍

    Micro:bit做为当红的少儿编程工具,这两年在编程教育领域越来越火.今天就从硬件架构开始,分享Micro:bit的相关主题. Microbit 硬件设计是根据ARM mbed技术所开发的应用IC及 ...

  6. MySQL三方面优化

    第一方面:30种mysql优化sql语句查询的方法1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中使用 ...

  7. lintcode514 栅栏染色

    栅栏染色 我们有一个栅栏,它有n个柱子,现在要给柱子染色,有k种颜色可以染.必须保证不存在超过2个相邻的柱子颜色相同,求有多少种染色方案. 注意事项 n和k都是非负整数 您在真实的面试中是否遇到过这个 ...

  8. 【20180807模拟测试】tree

    题目描述 或许会传送失败的传送门 #分析 考虑如何才能让白边显得更(不)重要,即在每条白边上(加上)减去一个值. 我们可以二分这个值,然后用寻常方法做最小生成树.统计在此最小生成树里有多少白 边. 然 ...

  9. Python中如何Getting Help

    在Python中Gettting Help有如下两种方法: 1 使用dir函数,dir的参数可以是一个真正的对象实例,也可以是一个数据类型,无论哪种情形,dir函数都返回与这个对象或者数据类型相关联的 ...

  10. 第一章 Windows编程基础(1~4课)

    第一课:从main到WinMain 第二课:窗口和消息 第三课:MFC编程 第四课:MFC应用程序框架 概括: Win32的两种编程框架:SDK方式.MFC方式 1. SDK方式:使用WinMain入 ...