单纯的暴搜似乎还是很好写的,然而过不了。出完顺子之后答案是可以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. hdu 2187(凸包直径 1.枚举 2.旋转卡壳)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 33115   Accepted: 10278 ...

  2. VINS(一)简介与代码结构

    VINS-Mono和VINS-Mobile是香港科技大学沈劭劼团队开源的单目视觉惯导SLAM方案.是基于优化和滑动窗口的VIO,使用IMU预积分构建紧耦合框架.并且具备自动初始化,在线外参标定,重定位 ...

  3. Ruby 基础教程1-5

    1.条件语句 if unless case        unless和if相反,条件不成立则执行   2.条件  除了 false和nil 其他都是true   3.unless 语法        ...

  4. CentOS 使用PostFix搭建邮件服务器

    搭建环境: 关于PostFix是什么以及邮件服务器接受发送邮件流程网上有很多文章,这里就不再写了,这里只记录如何搭建邮件服务器,使用PostFix接受发送邮件 CentOS6.8 32位,postfi ...

  5. java 素数问题

    1.素数 质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数. 2.java 实现 一般都要用不能被自己和其他数字整除判断,jdk中已经有更好的实现方法了. List<BigInte ...

  6. 分享一个 UiPath Studio 相关的公众号

    RPA 和 UiPath 方面的资料比较少,因此我们自己创建了一个公众号,专门用于传播 UiPath 相关的知识. 会定期发布 UiPath 学习相关的信息.是目前难得的 UiPath 中文资源. 公 ...

  7. hdu2098分拆素数和(素数+暴力)

    分拆素数和 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  8. Mac环境下RabbitMq安装与测试教程

    RabbitMq安装与测试教程 Installing on Mac I. 安装 123456789 brew install rabbitmq ## 进入安装目录cd /usr/local/Cella ...

  9. python3读取csv文件

    代码如下 import csv with open('D:\\abc\\userinfo.csv',newline='') as f: reader = csv.reader(f) for row i ...

  10. Siki_Unity_1-2_Unity5.2入门课程_进入Unity开发的奇幻世界_Roll A Ball

    1-2 Unity5.2入门课程 进入Unity开发的奇幻世界 任务1:Roll A Ball项目简介 Unity官网的tutorial入门项目 方向键控制小球在平台上滚动,碰撞方块得分,消掉所有方块 ...