单纯的暴搜似乎还是很好写的,然而过不了。出完顺子之后答案是可以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. Android stdio build.gradle buildscript 里面的repositories 和allprojects里面 repositories 的区别

    第一段 buildscript 里面的 repositories 表示只有编译工具才会用这个仓库. 比如 buildscript 里面的 dependencies classpath 'com.and ...

  2. 三 Hive 数据处理 自定义函数UDF和Transform

    三  Hive 自定义函数UDF和Transform 开篇提示: 快速链接beeline的方式: ./beeline -u jdbc:hive2://hadoop1:10000 -n hadoop 1 ...

  3. iWebShop安装教程

    要进行iWebShop测试,要先在本地电脑上安装iWebShop运行环境,之后再安装iWebShop程序,接下来我就一步步讲解,如何安装iWebShop程序. ##一.运行环境搭建 这里我推荐新手使用 ...

  4. TPO-14 C2 Prepare for a career in journalism

    TPO-14 C2 Prepare for a career in journalism 第 1 段 1.Listen to a conversation between a student and ...

  5. UniMelb Comp30022 IT Project (Capstone) - 1.Android入门

    1. Android入门 Android系统架构 Android系统:四层架构.五块区域 1. Linux内核层 Linux Kernel:为Android设备的硬件提供了底层驱动 2. 系统运行库层 ...

  6. 接口文档神器--apiui的使用

    接口开发,最麻烦的就是写文档了,曾经我也因为写接口文档苦不堪言:自从使用了apiui接口文档神器,工作效率和文档清晰得到了不止一个档次的提升. 下面介绍一下这个神器的使用: 把文件下载下来,放在网站根 ...

  7. 凸包算法(Graham扫描法)详解

    先说下基础知识,不然不好理解后面的东西 两向量的X乘p1(x1,y1),p2(x2,y2) p1Xp2如果小于零则说明  p1在p2的逆时针方向 如果大于零则说明 p1在p2的顺时针方向 struct ...

  8. ionic 获取input的值

    1.参数传递法 例子:获取input框内容 这里有个独特的地方,直接在input处使用 #定义参数的name值,注意在ts中参数的类型 在html页面中 <ion-input type=&quo ...

  9. I Hate It:线段树:单点修改+区间查询

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  10. 洛谷P1068 分数线划定:sort结构体排序+贪心

    题目描述 世博会志愿者的选拔工作正在 A 市如火如荼的进行.为了选拔最合适的人才,A市对所有报名的选手进行了笔试,笔试分数达到面试分数线的选手方可进入面试. 面试分数线根据计划录取人数的150%划定, ...