「NOIP2015」斗地主
传送门
Luogu
解题思路
给你们一张搜索顺序图,然后就大力模拟就好。
细节注意事项
- 爆搜题,你们懂的。。。
参考代码
写的有点丑了,洛谷上只能过加强版的88分,会T六个点
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
}
int n, ans, sum[25];
inline void dfs(int x) {
if (x >= ans) return;
int cnt = 0;
for (rg int i = 3; i <= 14; ++i) {
if (sum[i] < 1) cnt = 0;
else if ((++cnt) >= 5) {
for (rg int j = i - cnt + 1; j <= i; ++j) --sum[j];
dfs(x + 1);
for (rg int j = i - cnt + 1; j <= i; ++j) ++sum[j];
}
}
cnt = 0;
for (rg int i = 3; i <= 14; ++i) {
if (sum[i] < 2) cnt = 0;
else if ((++cnt) >= 3) {
for (rg int j = i - cnt + 1; j <= i; ++j) sum[j] -= 2;
dfs(x + 1);
for (rg int j = i - cnt + 1; j <= i; ++j) sum[j] += 2;
}
}
cnt = 0;
for (rg int i = 3; i <= 14; ++i) {
if (sum[i] < 3) cnt = 0;
else if ((++cnt) >= 2) {
for (rg int j = i - cnt + 1; j <= i; ++j) sum[j] -= 3;
dfs(x + 1);
for (rg int j = i - cnt + 1; j <= i; ++j) sum[j] += 3;
}
}
for (rg int i = 2; i <= 14; ++i) {
if (sum[i] >= 3) {
sum[i] -= 3;
for (rg int j = 2; j <= 15; ++j) {
if (i == j || sum[j] < 1) continue;
--sum[j], dfs(x + 1), ++sum[j];
}
for (rg int j = 2; j <= 14; ++j) {
if (i == j || sum[j] < 2) continue;
sum[j] -= 2, dfs(x + 1), sum[j] += 2;
}
sum[i] += 3;
}
if (sum[i] >= 4) {
sum[i] -= 4;
for (rg int j = 2; j <= 15; ++j) {
if (i == j || sum[j] < 1) continue;
--sum[j];
for (rg int k = 2; k <= 15; ++k) {
if (i == k || sum[k] < 1) continue;
--sum[k], dfs(x + 1), ++sum[k];
}
++sum[j];
}
for (rg int j = 2; j <= 14; ++j) {
if (i == j || sum[j] < 2) continue;
sum[j] -= 2;
for (rg int k = 2; k <= 14; ++k) {
if (i == k || sum[k] < 2) continue;
sum[k] -= 2, dfs(x + 1), sum[k] += 2;
}
sum[j] += 2;
}
sum[i] += 4;
}
}
for (rg int i = 2; i <= 15; ++i) x += sum[i] > 0;
ans = min(ans, x);
}
inline void solve() {
memset(sum, 0, sizeof sum);
for (rg int i = 1; i <= n; ++i) {
int x, y; read(x), read(y);
if (x == 0) ++sum[15];
else if (x == 1) ++sum[14];
else ++sum[x];
}
ans = 2147483647, dfs(0);
printf("%d\n", ans);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
int T; read(T), read(n);
while (T--) solve();
return 0;
}
完结撒花 \(qwq\)
「NOIP2015」斗地主的更多相关文章
- LG2679 「NOIP2015」子串 线性DP
问题描述 LG2679 题解 设\(opt[i][j]\)代表A串前\(i\)个,匹配\(B\)串前\(j\)个,选择了\(k\)个子串的方案数. 转移用前缀和优化一下. \(\mathrm{Code ...
- loj2425 「NOIP2015」运输计划[二分答案+树上差分]
看到题意最小化最长路径,显然二分答案,枚举链长度不超过$\text{mid}$,然后尝试检验.````` 检验是否存在这样一个边置为0后,全部链长$\le\text{mid}$,其最终目标就是.要让所 ...
- loj2424 「NOIP2015」子串[字符串DP]
给定字符串 A,B,要求从 A 中取出互不重叠的 k 个非空子串,按照出现顺序拼起来后等于 B.求方案数.n ≤ 1000,m ≤ 200. 主要是状态的转移.先设计出$f_{i,j,k}$表长度$B ...
- 「NOIP2015」运输计划
传送门 Luogu 解题思路 首先这题可以直接二分答案,然后我们每次都把属于长度大于二分值的路径上的边标记一次,表示选这条边可以优化几条路径. 然后我们显然是要选一条覆盖次数等于需要覆盖的路径数并且长 ...
- 「译」JUnit 5 系列:条件测试
原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...
- 「译」JUnit 5 系列:扩展模型(Extension Model)
原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...
- JavaScript OOP 之「创建对象」
工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...
- 「C++」理解智能指针
维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...
- 「JavaScript」四种跨域方式详解
超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...
随机推荐
- 忘记linux下的mysql密码,需要重新创建密码123456
你必须要有操作系统的root权限了. # mysqld_safe --skip-grant-tables & &,表示在后台运行,不再后台运行的话,就再打开一个终端咯. # mysql ...
- WLC-生成CSR操作
1.生成CSR [req]req_extensions = v3_req[ v3_req ]# Extensions to add to a certificate requestbasicConst ...
- StudentManagerSSM
web.xml StudentManagerSSM.rar <?xml version="1.0" encoding="UTF-8&quo ...
- Maven____笔记摘抄
1 1.maven的作用 i.增加第三方Jar (spring-context.jar spring-aop.jar ....) ii.jar包之间的依赖关系 (spring-context.jar ...
- python 顺序执行任务
#!/usr/bin/python import os import time start_command="sh start-etl.sh " es_mac_confPath = ...
- 理解js中的原型链
对象有”prototype”属性,函数对象有”prototype”属性,原型对象有”constructor”属性. 关于原型 在JavaScript中,原型也是一个对象,通过原型可以实现对象的属性继承 ...
- 工具 - gravatar保存头像
流程 注册账号,上传头像 https://secure.gravatar.com/avatar/ 就可以获取到头像 参数 例子flasky git reset --hard 10c def grava ...
- Python 爬取 热词并进行分类数据分析-[拓扑数据]
日期:2020.01.29 博客期:137 星期三 [本博客的代码如若要使用,请在下方评论区留言,之后再用(就是跟我说一声)] 所有相关跳转: a.[简单准备] b.[云图制作+数据导入] c.[拓扑 ...
- windows中共存python2和python3以及各自pip的配置
到官网下载相应系统的python2和python3的安装程序 官网链接:https://www.python.org/ 下载完成后,如下两个安装程序 分别把python2的安装程序和python3的放 ...
- django annotate()的使用
https://www.zmrenwu.com/post/18/ 博客文章通常都有分类,有时候我们会看到分类名后面还跟着该分类下的文章数量.前面我们通过学习 django 博客开发入门教程搭建了一个小 ...