传送门

Luogu

解题思路

给你们一张搜索顺序图,然后就大力模拟就好。

细节注意事项

  • 爆搜题,你们懂的。。。

参考代码

写的有点丑了,洛谷上只能过加强版的88分,会T六个点

  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cstdio>
  6. #include <cctype>
  7. #include <cmath>
  8. #include <ctime>
  9. #define rg register
  10. using namespace std;
  11. template < typename T > inline void read(T& s) {
  12. s = 0; int f = 0; char c = getchar();
  13. while (!isdigit(c)) f |= c == '-', c = getchar();
  14. while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
  15. s = f ? -s : s;
  16. }
  17. int n, ans, sum[25];
  18. inline void dfs(int x) {
  19. if (x >= ans) return;
  20. int cnt = 0;
  21. for (rg int i = 3; i <= 14; ++i) {
  22. if (sum[i] < 1) cnt = 0;
  23. else if ((++cnt) >= 5) {
  24. for (rg int j = i - cnt + 1; j <= i; ++j) --sum[j];
  25. dfs(x + 1);
  26. for (rg int j = i - cnt + 1; j <= i; ++j) ++sum[j];
  27. }
  28. }
  29. cnt = 0;
  30. for (rg int i = 3; i <= 14; ++i) {
  31. if (sum[i] < 2) cnt = 0;
  32. else if ((++cnt) >= 3) {
  33. for (rg int j = i - cnt + 1; j <= i; ++j) sum[j] -= 2;
  34. dfs(x + 1);
  35. for (rg int j = i - cnt + 1; j <= i; ++j) sum[j] += 2;
  36. }
  37. }
  38. cnt = 0;
  39. for (rg int i = 3; i <= 14; ++i) {
  40. if (sum[i] < 3) cnt = 0;
  41. else if ((++cnt) >= 2) {
  42. for (rg int j = i - cnt + 1; j <= i; ++j) sum[j] -= 3;
  43. dfs(x + 1);
  44. for (rg int j = i - cnt + 1; j <= i; ++j) sum[j] += 3;
  45. }
  46. }
  47. for (rg int i = 2; i <= 14; ++i) {
  48. if (sum[i] >= 3) {
  49. sum[i] -= 3;
  50. for (rg int j = 2; j <= 15; ++j) {
  51. if (i == j || sum[j] < 1) continue;
  52. --sum[j], dfs(x + 1), ++sum[j];
  53. }
  54. for (rg int j = 2; j <= 14; ++j) {
  55. if (i == j || sum[j] < 2) continue;
  56. sum[j] -= 2, dfs(x + 1), sum[j] += 2;
  57. }
  58. sum[i] += 3;
  59. }
  60. if (sum[i] >= 4) {
  61. sum[i] -= 4;
  62. for (rg int j = 2; j <= 15; ++j) {
  63. if (i == j || sum[j] < 1) continue;
  64. --sum[j];
  65. for (rg int k = 2; k <= 15; ++k) {
  66. if (i == k || sum[k] < 1) continue;
  67. --sum[k], dfs(x + 1), ++sum[k];
  68. }
  69. ++sum[j];
  70. }
  71. for (rg int j = 2; j <= 14; ++j) {
  72. if (i == j || sum[j] < 2) continue;
  73. sum[j] -= 2;
  74. for (rg int k = 2; k <= 14; ++k) {
  75. if (i == k || sum[k] < 2) continue;
  76. sum[k] -= 2, dfs(x + 1), sum[k] += 2;
  77. }
  78. sum[j] += 2;
  79. }
  80. sum[i] += 4;
  81. }
  82. }
  83. for (rg int i = 2; i <= 15; ++i) x += sum[i] > 0;
  84. ans = min(ans, x);
  85. }
  86. inline void solve() {
  87. memset(sum, 0, sizeof sum);
  88. for (rg int i = 1; i <= n; ++i) {
  89. int x, y; read(x), read(y);
  90. if (x == 0) ++sum[15];
  91. else if (x == 1) ++sum[14];
  92. else ++sum[x];
  93. }
  94. ans = 2147483647, dfs(0);
  95. printf("%d\n", ans);
  96. }
  97. int main() {
  98. #ifndef ONLINE_JUDGE
  99. freopen("in.in", "r", stdin);
  100. #endif
  101. int T; read(T), read(n);
  102. while (T--) solve();
  103. return 0;
  104. }

完结撒花 \(qwq\)

「NOIP2015」斗地主的更多相关文章

  1. LG2679 「NOIP2015」子串 线性DP

    问题描述 LG2679 题解 设\(opt[i][j]\)代表A串前\(i\)个,匹配\(B\)串前\(j\)个,选择了\(k\)个子串的方案数. 转移用前缀和优化一下. \(\mathrm{Code ...

  2. loj2425 「NOIP2015」运输计划[二分答案+树上差分]

    看到题意最小化最长路径,显然二分答案,枚举链长度不超过$\text{mid}$,然后尝试检验.````` 检验是否存在这样一个边置为0后,全部链长$\le\text{mid}$,其最终目标就是.要让所 ...

  3. loj2424 「NOIP2015」子串[字符串DP]

    给定字符串 A,B,要求从 A 中取出互不重叠的 k 个非空子串,按照出现顺序拼起来后等于 B.求方案数.n ≤ 1000,m ≤ 200. 主要是状态的转移.先设计出$f_{i,j,k}$表长度$B ...

  4. 「NOIP2015」运输计划

    传送门 Luogu 解题思路 首先这题可以直接二分答案,然后我们每次都把属于长度大于二分值的路径上的边标记一次,表示选这条边可以优化几条路径. 然后我们显然是要选一条覆盖次数等于需要覆盖的路径数并且长 ...

  5. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  6. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

  7. JavaScript OOP 之「创建对象」

    工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...

  8. 「C++」理解智能指针

    维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...

  9. 「JavaScript」四种跨域方式详解

    超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...

随机推荐

  1. 忘记linux下的mysql密码,需要重新创建密码123456

    你必须要有操作系统的root权限了. # mysqld_safe --skip-grant-tables & &,表示在后台运行,不再后台运行的话,就再打开一个终端咯. # mysql ...

  2. WLC-生成CSR操作

    1.生成CSR [req]req_extensions = v3_req[ v3_req ]# Extensions to add to a certificate requestbasicConst ...

  3. StudentManagerSSM

    web.xml              StudentManagerSSM.rar <?xml version="1.0" encoding="UTF-8&quo ...

  4. Maven____笔记摘抄

    1 1.maven的作用 i.增加第三方Jar (spring-context.jar spring-aop.jar ....) ii.jar包之间的依赖关系 (spring-context.jar ...

  5. python 顺序执行任务

    #!/usr/bin/python import os import time start_command="sh start-etl.sh " es_mac_confPath = ...

  6. 理解js中的原型链

    对象有”prototype”属性,函数对象有”prototype”属性,原型对象有”constructor”属性. 关于原型 在JavaScript中,原型也是一个对象,通过原型可以实现对象的属性继承 ...

  7. 工具 - gravatar保存头像

    流程 注册账号,上传头像 https://secure.gravatar.com/avatar/ 就可以获取到头像 参数 例子flasky git reset --hard 10c def grava ...

  8. Python 爬取 热词并进行分类数据分析-[拓扑数据]

    日期:2020.01.29 博客期:137 星期三 [本博客的代码如若要使用,请在下方评论区留言,之后再用(就是跟我说一声)] 所有相关跳转: a.[简单准备] b.[云图制作+数据导入] c.[拓扑 ...

  9. windows中共存python2和python3以及各自pip的配置

    到官网下载相应系统的python2和python3的安装程序 官网链接:https://www.python.org/ 下载完成后,如下两个安装程序 分别把python2的安装程序和python3的放 ...

  10. django annotate()的使用

    https://www.zmrenwu.com/post/18/ 博客文章通常都有分类,有时候我们会看到分类名后面还跟着该分类下的文章数量.前面我们通过学习 django 博客开发入门教程搭建了一个小 ...