POJ 1321 棋盘问题
来源:互联网 发布:js除以10000四舍五入 编辑:程序博客网 时间:2024/05/16 15:19
百年难得一遇的会做的中文题......
每一次DFS都有两种状态 放或者不放 简单的DFS模板题。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cmath> 6 7 using namespace std; 8 9 int n,k,sum;10 11 char map[10][10];12 13 bool HashH[10],HashW[10];14 15 void dfs(int h,int w,int kc)16 {17 int i,j;18 19 if(kc == k)20 {21 ++sum;22 return ;23 }24 25 for(i = h; i <= n; ++i)26 {27 for(j = (i == h ? w+1 : 1); j <= n; ++j)28 if(map[i][j] == '#' && HashH[i] == false && HashW[j] == false)29 break;30 if(j != n+1)31 break;32 }33 34 if(map[i][j] == '#')35 {36 HashH[i] = true;37 HashW[j] = true;38 dfs(i,j,kc+1);39 HashH[i] = false;40 HashW[j] = false;41 dfs(i,j,kc);42 }43 }44 45 int main()46 {47 int i;48 while(scanf("%d %d",&n,&k) && (n != -1 || k != -1))49 {50 51 sum = 0;52 53 memset(HashH,false,sizeof(HashH));54 memset(HashW,false,sizeof(HashW));55 56 for(i = 1; i <= n; ++i)57 {58 scanf("%s",map[i]+1);59 }60 61 dfs(1,0,0);62 63 printf("%d\n",sum);64 }65 return 0;66 }
- POJ 1321 棋盘问题
- poj 1321 棋盘问题
- poj 1321 棋盘问题
- Poj 1321 棋盘问题
- POJ 1321 棋盘问题
- POJ 1321 棋盘问题
- POJ-1321-棋盘问题
- poj 1321棋盘问题
- POJ 1321 棋盘问题
- poj 1321 棋盘问题
- POJ 1321 棋盘问题
- poj 1321 棋盘问题
- poj 1321 棋盘问题
- poj 1321 棋盘问题
- poj 1321 棋盘问题
- POJ 1321 - 棋盘问题
- poj 1321棋盘问题
- POJ 1321 棋盘问题
- POJ 1442 Black Box
- POJ 2488 A Knight's Journey
- Java程序打包成jar包
- Grand Central Dispatch(GCD)初探
- POJ 2418 Hardwood Species
- POJ 1321 棋盘问题
- c++语法
- POJ 2251 Dungeon Master
- POJ 3126 Prime Path
- POJ 3087 Shuffle'm Up
- POJ 3414 Pots
- POJ 2676 sudoku
- POJ 1129 Channel Allocation
- POJ 1416 Shredding Company