POJ-1321-棋盘问题
http://poj.org/problem?id=1321
基本的DFS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int n,t,ans;
char map[10][10];
int visit[10];
void dfs(int x,int y)
{
int i;
if(y==t)
{
ans++;
return;
}
if(x>=n)
return;
for(i=0;i<n;i++) //x行放棋子
{
if(!visit[i]&&map[x][i]=='#')
{
visit[i]=1;
dfs(x+1,y+1);
visit[i]=0;
}
}
dfs(x+1,y); //x行不放棋子
}
int main()
{
int i;
while(scanf("%d%d",&n,&t),n!=-1&&t!=-1)
{
for(i=0;i<n;i++)
scanf("%s",map[i]);
ans=0;
memset(visit,0,sizeof(visit));
dfs(0,0);
printf("%d\n",ans);
}
return 0;
}
分享到:
相关推荐
POJ1321棋盘问题 很好两种解法很值得去参考一下 完整的实验报告还有代码希望kan
poj-1002源码,没有题解,题解看博客poj-1002源码,没有题解,题解看博客poj-1002源码,没有题解,题解看博客poj-1002源码,没有题解,题解看博客
北大POJ1321-Chess Problem POJ1321-Chess Problem
POJ---1456.Supermarket测试数据及答案,题目描述:A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral ...
POJ-3299解题 C++源代码 Description Adapted from Wikipedia, the free encyclopedia The humidex is a measurement used by Canadian meteorologists to reflect the combined effect of heat and humidity. It...
算法-开关问题(POJ-1830)(包含源程序).rar
西北工业大学-c语言-POJ-题目及答案-第七季.doc
poj-2528 Mayor's posters 测试数据及答案
poj 1000 - 2000 部分题目 官方分类 poj 1000 - 2000 部分题目 官方分类
北大POJ2002-Squares 解题报告+AC代码
算法-炮兵阵地(POJ-1185)(包含源程序).rar
算法-青蛙的约会(POJ-1061)(包含源程序).rar
北大POJ3253-POJ3253-Fence Repair【STL优先队列】 解题报告+AC代码
北大POJ2525-Text Formalization【TrieTree】 解题报告+AC代码+测试数据 http://hi.csdn.net/!s/XW4FQ3