[ACM] POJ 3740 Easy Finding (DFS)
来源:互联网 发布:苹果看视频软件 编辑:程序博客网 时间:2024/05/16 20:28
Easy Finding
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 16482 Accepted: 4476
Description
Given a M×N matrix A. Aij ∈ {0, 1} (0 ≤ i < M, 0 ≤ j < N), could you find some rows that let every cloumn contains and only contains one 1.
Input
There are multiple cases ended by EOF. Test case up to 500.The first line of input is M, N (M ≤ 16, N ≤ 300). The next M lines every line contains N integers separated by space.
Output
For each test case, if you could find it output "Yes, I found it", otherwise output "It is impossible" per line.
Sample Input
3 30 1 00 0 11 0 04 40 0 0 11 0 0 01 1 0 10 1 0 0
Sample Output
Yes, I found itIt is impossible
Source
POJ Monthly Contest - 2009.08.23, MasterLuo
解题思路:
题意为给出n*m的01矩阵,问能不能从中选出一些行,使得这些行组成的新矩阵中,每列有且只有一个1.
本题用Dlx可解,明显的完全覆盖问题。这里练习DFs,用DFS按照行号递增的顺序枚举行就可以.一开始犯了一个很严重的错误,就是没有按行号递增的顺序,导致了重复,其实 1 2 5和 5 1 2其实是一样的,所以DFS(int row), 参数是行号,下一层递归为DFs(row+1), 每次进入DFs都要首先判断是否符合题意,即新矩阵每列有且只有一个1,用vis[j]数组表示新矩阵中第j列是否已经有一个1,如果满足该条件,就不用往下继续递归了,直接标记成功,return即可。
通过这道题,加深了对递归的理解,感觉只要想明白,递归也不是那么难理解。
假设当n=4时,搜索的行号是按这样的顺序:
1
1 2
1 2 3
1 2 3 4
1 2 4
1 3
1 3 4
1 4
2
2 3
2 3 4
2 4
3
3 4
4
代码:
0 0
- [ACM] POJ 3740 Easy Finding (DFS)
- [ACM] POJ 3740 Easy Finding (DFS)
- [ACM] POJ 3740 Easy Finding (DFS)
- POJ 3740 Easy Finding(dfs回溯)
- POJ 3740 Easy Finding
- poj 3740 Easy Finding
- poj 3740 Easy Finding
- POJ 3740 Easy Finding
- poj-3740 Easy Finding
- [ACM] POJ 3740 Easy Finding (DLX模板题)
- POJ 3740 Easy Finding 位运算压缩+DFS or Dancing Links
- POJ-3740(dfs边界点和还原处理)(Easy Finding)
- POJ 3740 Easy Finding 详细讲解
- POJ 3740 Easy Finding(舞蹈链)
- poj 3740 Easy Finding 搜索+位运算
- poj 3740 Easy Finding(Dancing Links)
- POJ 3740 - Easy Finding (Dancing links)
- POJ 3740 Easy Finding (DLX模板)
- Android中JNI的使用方法
- 类和对象
- Eclipse --- 常用配置及快捷键
- 黑马程序员——类与对象
- C++基础---有返回值类型函数(返回非引用类型)
- [ACM] POJ 3740 Easy Finding (DFS)
- ado 使用
- JavaScript知识点总结-4
- [ACM] FZU 2092 收集水晶 (DFS,记忆化搜索)
- Scala深入浅出实战经典第82讲
- 计划
- ios开发中的官方地图(CLLocationManager)使用
- 数据同步平台——FTP
- 找不到lua_open