传送门

Luogu

解题思路

这题其实挺简单的。

首先要熟悉数独,我们应该要优先搜索限制条件多的行,也就是可能方案少的行,显然这样可以剪枝,然后再发挥一下dfs的基本功就可以了。

细节注意事项

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

参考代码

#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;
} const int s[10][10] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 6, 6, 6, 6, 6, 6, 6, 6, 6 },
{ 0, 6, 7, 7, 7, 7, 7, 7, 7, 6 },
{ 0, 6, 7, 8, 8, 8, 8, 8, 7, 6 },
{ 0, 6, 7, 8, 9, 9, 9, 8, 7, 6 },
{ 0, 6, 7, 8, 9,10, 9, 8, 7, 6 },
{ 0, 6, 7, 8, 9, 9, 9, 8, 7, 6 },
{ 0, 6, 7, 8, 8, 8, 8, 8, 7, 6 },
{ 0, 6, 7, 7, 7, 7, 7, 7, 7, 6 },
{ 0, 6, 6, 6, 6, 6, 6, 6, 6, 6 }
}; const int p[10][10] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 1, 1, 1, 2, 2, 2, 3, 3, 3 },
{ 0, 1, 1, 1, 2, 2, 2, 3, 3, 3 },
{ 0, 1, 1, 1, 2, 2, 2, 3, 3, 3 },
{ 0, 4, 4, 4, 5, 5, 5, 6, 6, 6 },
{ 0, 4, 4, 4, 5, 5, 5, 6, 6, 6 },
{ 0, 4, 4, 4, 5, 5, 5, 6, 6, 6 },
{ 0, 7, 7, 7, 8, 8, 8, 9, 9, 9 },
{ 0, 7, 7, 7, 8, 8, 8, 9, 9, 9 },
{ 0, 7, 7, 7, 8, 8, 8, 9, 9, 9 },
}; struct node { int id, cnt; }a[10];
inline bool cmp(const node& x, const node& y) { return x.cnt > y.cnt; }
int ans = -1, mp[10][10]; bool Line[10][10], Clmn[10][10], Palc[10][10]; inline void dfs(int i, int j, int line, int sum) {
if (line > 9) { ans = max(ans, sum); return; }
if (j == 10) { dfs(a[line + 1].id, 1, line + 1, sum); return ; }
if (mp[i][j]) { dfs(i, j + 1, line, sum); return; }
for (rg int x = 1; x <= 9; ++x) {
if (Line[i][x]) continue;
if (Clmn[j][x]) continue;
if (Palc[p[i][j]][x]) continue;
Line[i][x] = Clmn[j][x] = Palc[p[i][j]][x] = 1, mp[i][j] = x;
dfs(i, j + 1, line, sum + x * s[i][j]);
Line[i][x] = Clmn[j][x] = Palc[p[i][j]][x] = 0, mp[i][j] = 0;
}
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
for (rg int i = 1; i <= 9; ++i) a[i].id = i;
int tmp = 0;
for (rg int i = 1; i <= 9; ++i)
for (rg int j = 1; j <= 9; ++j) {
int x; read(x), mp[i][j] = x;
if (x) Line[i][x] = 1, Clmn[j][x] = 1, Palc[p[i][j]][x] = 1, ++a[i].cnt, tmp += x * s[i][j];
}
sort(a + 1, a + 10, cmp);
dfs(a[1].id, 1, 0, tmp);
printf("%d\n", ans);
return 0;
}

完结撒花 \(qwq\)

「NOIP2009」靶形数独的更多相关文章

  1. 「NOIP2009」最优贸易 题解

    「NOIP2009」最优贸易 题解 题目TP门 题目描述 \(C\)国有\(n\)个大城市和\(m\)条道路,每条道路连接这\(n\)个城市中的某两个城市.任意两个城市之间最多只有一条道路直接相连.这 ...

  2. 「NOIP2009」最优贸易

    「NOIP2009」最优贸易 「NOIP2009」最优贸易内存限制:128 MiB时间限制:1000 ms 题目描述C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意 ...

  3. 「NOIP2009」Hankson 的趣味题

    Hankson 的趣味题 [内存限制:$128 MiB$][时间限制:$1000 ms$] [标准输入输出][题目类型:传统][评测方式:文本比较] 题目描述 Hanks 博士是 BT(Bio-Tec ...

  4. 【noip2009】靶形数独

    题解: 又是搜索- - 加状态压缩剪枝 二进制记下每行 每列 每个九宫格用过的数是谁 枚举的时候可以O(1)判断冲突 还有个很重要的剪枝 把可能使用数字最少的格子先搜索 代码: #include &l ...

  5. #2590. 「NOIP2009」最优贸易

    C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个城市之间最多只有一条道路直接相连.这 m 条道路中有一部分为单向通行的道路,一部分为双向通行的道路,双向通行的道 ...

  6. loj2589 「NOIP2009」Hankson 的趣味题

    对于质因数分解理解还不到位. 此题可知$lcm$是$x$的倍数,$x$是$lcm$的约数,只要在$lcm$的分解质因数里对每一个质因子讨论种数即可. 具体来说,对于$lcm$的一个质因子$p$,讨论$ ...

  7. 「NOIP2009」Hankson的趣味题

    题目描述 (由于本题是数论题,所以我只把题目大意说一下...) 输入时给定\(a_0,a_1,b_0,b_1\),题目要求你求出满足如下条件的\(x\)的个数: \[\begin{cases}\gcd ...

  8. 靶形数独 (dfs+预处理+状态压缩)

    #2591. 「NOIP2009」靶形数独 [题目描述] 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们 ...

  9. NOIP2009靶形数独(暴搜)

    题目传送门 题目描述 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们向Z博士请教,Z博士拿出了他最近发明 ...

随机推荐

  1. WinForm开发(4)——使用Visual-Studio-2010-打包安装程序

    打包程序: 1,解决方案—右键菜单“添加”—新建项目—其他项目类型—安装和部署—Visual Studio Installer—安装项目,输入名称Setup1,点“确定” 2,添加开始程序中的文件夹: ...

  2. DOCKSWARM服务网络原理

    如图所示,我们将在 swarm 集群中部署 “client” 服务 和 “vote” 服务,其中 “vote” 服务部署多个副本. 客户端请求 “vote” 服务时,输出结果中包含服务端的容器 ID, ...

  3. 线程池三种队列使用,SynchronousQueue,LinkedBlockingQueue,ArrayBlockingQueue

    使用方法: private static ExecutorService cachedThreadPool = new ThreadPoolExecutor(4, Runtime.getRuntime ...

  4. Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig

    Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig at ...

  5. Selenium 页面加载慢

    Selenium 页面加载慢 问题描述: 使用Selenium获取网页,发现webdriver.get方法会阻塞直到网页全部加载完成,官方提供的三种wait方法仅对网页的ajax有比较明显的效果.对于 ...

  6. 从零构建以太坊(Ethereum)智能合约到项目实战——第20章 搭建自己的私有链网络

    P75 .1-以太坊私网建立 .合约编译.部署完全教程(1) 使用此博文进行安装配置:https://blog.csdn.net/w88193363/article/details/79402074 ...

  7. 吴裕雄--天生自然ORACLE数据库学习笔记:过程、函数、触发器和包

    create procedure pro_insertDept is begin ,'市场拓展部','JILIN'); --插入数据记录 commit; --提交数据 dbms_output.put_ ...

  8. Linux 添加新磁盘 && 创建分区 && 挂载

    参考: 挂载目录 分区:https://blog.csdn.net/arenn/article/details/78866251 挂载:https://www.jb51.net/article/108 ...

  9. linux 环境下安装jdk

    参考:https://blog.csdn.net/qq_30788949/article/details/81975954 安装 参考: https://www.cnblogs.com/shihaim ...

  10. Android游戏开发学习(5)--实现Button悬浮于与SurfaceView之上

    原文:http://daikainan.iteye.com/blog/1407355 实现Button悬浮于与SurfaceView之上实现 先看效果: 注意:你实现的SurfaceView和andr ...