寒假集训——搜索 D - Cubes for Masha
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
using namespace std;
int num[4][10],n;
int vis[1100],exa[10]; void dfs(int ceng,int s)
{
vis[s]=1;
if(ceng>=n) return;
for(int i=1;i<=n;i++)
{
if(exa[i]) continue;
for(int j=1;j<=6;j++)
{
exa[i]=1;
dfs(ceng+1,s*10+num[i][j]);
exa[i]=0;
}
}
} int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(vis,0,sizeof(vis));
memset(exa,0,sizeof(exa));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=6;j++)
{
scanf("%d",&num[i][j]);
}
}
dfs(0,0);
int mark;
for(int i=1;i<1000;i++)
{
if(!vis[i])
{
mark=i-1;
break;
}
}
printf("%d\n",mark);
}
return 0;
}
Absent-minded Masha got set of n cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x.
To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number.
The number can't contain leading zeros. It's not required to use all cubes to build a number.
Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations.
Input
In first line integer n is given (1 ≤ n ≤ 3) — the number of cubes, Masha got for her birthday.
Each of next n lines contains 6 integers aij (0 ≤ aij ≤ 9) — number on j-th face of i-th cube.
Output
Print single integer — maximum number x such Masha can make any integers from 1 to x using her cubes or 0 if Masha can't make even 1.
Examples
3
0 1 2 3 4 5
6 7 8 9 0 1
2 3 4 5 6 7
87
3
0 1 3 5 6 8
1 2 4 5 7 8
2 3 4 6 7 9
98
Note
In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8.
题目:D - Cubes for Masha
思路:
因为最多为三个魔方,意思是数字最大为999
所以可以采用枚举遍历的方法。
简单来说,就是用搜索把三个魔法可以组成的所有的数全部搜出来,然后找到最近的断点。
具体:
用一个二维数组,或者三个一维数组储存魔方上的六个数。
用vis数组来表示这个数是否存在,1存在,0不存在。
搜索里面,注意一个魔方不能同时用上面的两个数,所以要用东西标记这个魔方是否用过了
寒假集训——搜索 D - Cubes for Masha的更多相关文章
- 寒假集训——搜索 B - Sudoku
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream&g ...
- codeforces 887B Cubes for Masha 两种暴力
B. Cubes for Masha time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CSU-ACM寒假集训选拔-入门题
CSU-ACM寒假集训选拔-入门题 仅选择部分有价值的题 J(2165): 时间旅行 Description 假设 Bobo 位于时间轴(数轴)上 t0 点,他要使用时间机器回到区间 (0, h] 中 ...
- HZNU-ACM寒假集训Day3小结 搜索
简单搜索 1.DFS UVA 548 树 1.可以用数组方式实现二叉树,在申请结点时仍用“动态化静态”的思想,写newnode函数 2.给定二叉树的中序遍历和后序遍历,可以构造出这棵二叉树,方法是根据 ...
- 2022寒假集训day2
day1:学习seach和回溯,初步了解. day2:深度优化搜索 T1 洛谷P157:https://www.luogu.com.cn/problem/P1157 题目描述 排列与组合是常用的数学方 ...
- 2014 UESTC暑前集训搜索专题解题报告
A.解救小Q BFS.每次到达一个状态时看是否是在传送阵的一点上,是则传送到另一点即可. 代码: #include <iostream> #include <cstdio> # ...
- 寒假训练——搜索 K - Cycle
A tournament is a directed graph without self-loops in which every pair of vertexes is connected by ...
- 寒假训练——搜索 E - Bloxorz I
Little Tom loves playing games. One day he downloads a little computer game called 'Bloxorz' which m ...
- poj3984《迷宫问题》暑假集训-搜索进阶
K - 迷宫问题 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
随机推荐
- maven package,clean,install,compile命令
1.Ideal中显示 2.各个阶段干嘛的? compile,编译命令,会在项目路径下生成一个target目录,在该目录中包含一个classes文件夹,里面全是生成的class文件及字节码文件 pack ...
- Django models 常用数据类型
CharField class CharField(max_length=None[, **options]) # 字符串(存储从小到大各种长度) # 如果是巨大的文本类型,可以用 TextField ...
- 《Photoshop CS4手绘艺术技法》
书名 <Photoshop CS4手绘艺术技法> 图片 时间 2017-4月 学习 想了想当初的学习动机,自己P图片可是P的是实在是丑就会做几张动图.看完了才发现这行博大精深而且自己的审 ...
- ILSpy
今日为找泛型序列的一个Select方法源码,就去找了个ILSpy反编译工具. 工具下载地址:http://www.fishlee.net/service/softarchive/57,一般选择较新的. ...
- maven 如何依赖工程项目里面的 jar 包
前言:现在有个 jar 包在私服和公共仓库里面都没有,需要自己将 jar 包放在工程里,然后让 maven 依赖. 这里举个栗子 项目路径: pom.xml 配置 <!--自定义查询组件的jar ...
- 使用Java解析XML
一.解析的对象 <?xml version="1.0" encoding="UTF-8"?> <users> <user id=& ...
- JavaScript--水平幻灯片
// 列表布局,图片左浮动,外侧容器设置overflow:hidden; // 组合使用构造函数模式(对象不共享的数据)和原型模式(对象共享的数据) <!DOCTYPE html> < ...
- JqGrid: Add,Edit,Del in asp.net
https://github.com/1rosehip/jplist https://github.com/free-jqgrid/jqGrid https://plugins.jquery.com/ ...
- 【读书笔记】iOS-iOS流媒体
在网络上直接看电影已经不是什么新鲜的事情,在iOS等移动设备上也有很多在线视频应用,如国内的PPS和PPLive应用,还有一些新闻视频都可以在线观看,如USA TODY.所以这些在线视频都采用流媒体技 ...
- 【读书笔记】iOS-正则表达式
正则表达式通常称为regexes,是文本处理中模式匹配的一个标准,也是处理字符串的一个强有力的工具.使用正则表达式时,需要指定一个字符串作为模式串去检索目标字符串.你可以使用正则表达式来查找字符串中匹 ...