思路:记录每行每列每一个宫已经出现的数字就可以.数据比較弱 另外POJ 3074 3076 必须用剪枝策略.但实现较麻烦,还是以后学了DLX再来做吧 //Accepted 160K 0MS #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int N =15; char sudo[N][N]; bool vi…
Sudoku Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the Figure. In some of the cells are written decimal digits from 1 to 9. The other cells are empty. The goal is to fill the…
Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13665   Accepted: 6767   Special Judge Description Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the Figure.…
POJ 1321-棋盘问题 K - DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u   Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C. Input 输入含有多组测试数据. 每组数据的第一行是两个正整数,n k…
题目链接:http://poj.org/problem?id=3740 题意: 是否从0,1矩阵中选出若干行,使得新的矩阵每一列有且仅有一个1? 原矩阵N*M $ 1<= N <= 16 $ , $ 1 <= M <= 300$ 解法1:由于行数不多,二进制枚举选出的行数,时间复杂度为O((1<<16)*K), 其中K即为判断选出的行数是否存在相同的列中有重复的1: 优化:将1状压即可,这样300的列值,压缩在int的32位中,使得列数“好像”小于10了:这样每次只需要…
  Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14368   Accepted: 7102   Special Judge Description Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the Figure. In so…
题意:完成数独程序,数独要求每行每列且每个3*3矩阵都必须是1~9的数字组成. 思路:dfs 用row[i][n] 记录第i行n存在  用col[j][n] 记录第j列n存在 grid[k][n] 记录第k个3*3中的n存在 遍历的时候,先把列遍历完然后在遍历行 if (map[r][c]) { ) flag = dfs(r + , ); ); return flag; } 现在推 第一个矩阵为  0,0 0,1 0,2              第二个矩阵为   0,3 0,4 0,5 1,0…
题目:Sudoku 题意:求解数独.从样例和结果来看应该是简单难度的数独 思路:DFS 设置3个数组,row[i][j] 判断第i行是否放了j数字,col[i][j] 判断第i列是否放了j数字.square[i/3][j/3][x]判断第i/3行第j/3列个宫是否放置了x数字: #include <iostream> #include <algorithm> #include <stdlib.h> #include <time.h> #include <…
链接:http://poj.org/problem?id=2386 题解 #include<cstdio> #include<stack> using namespace std; ,MAX_N=; char a[MAX_N][MAX_M]; int N,M; //现在位置 (x,y) void dfs(int x,int y){ a[x][y]='.'; //将现在所在位置替换为'.',即旱地 ;dx<=;dx++){ //循环遍历连通的8个方向:上.下.左.右.左上.左下…
Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25904   Accepted: 7682 Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been…