摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2553//1.非递归:#include <cstdio>#include <cmath>using namespace std;#define N 13int x[N];bool isvalid(int k){ int i; for(i=0; i<k; i++) if(x[i]==x[k] || abs(x[i]-x[k])==abs(i-k)) return false; return true;}int queen(int n){ int k=0,count=0; x[k]= 阅读全文
posted @ 2011-03-24 23:14 CoderZhuang 阅读(129) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1016输入n。从1到n的数组成一个环,环相邻的两个数之和为质数。输出所有的这种环。本人用深搜递归水过250ms#include <stdio.h>#include<stdlib.h>#include<string.h>#include <iostream>using namespace std;int n;int ans[25],p[50],flag[25];void dfs(int step){ int i; if(step==n) { if(p[ans[0] 阅读全文
posted @ 2011-03-24 11:24 CoderZhuang 阅读(109) 评论(0) 推荐(0) 编辑