
DFS回溯
文章平均质量分 58
TodorovChen
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
8.7-硬币组合
#include using namespace std;int cent[]={25,10,5,1};int n=21;int tot=0;void dfs_order(int cur){ if(cur>n) return; if(cur==n) { tot++; } else for(int i=0;i<4;i原创 2014-09-08 09:58:44 · 685 阅读 · 0 评论 -
DFS回溯标记什么时候需要还原
1.如果是visit[i]这种标记,如果回溯后原创 2014-08-13 11:36:00 · 5498 阅读 · 3 评论 -
Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()原创 2014-04-24 16:10:29 · 409 阅读 · 0 评论 -
【Wikioi】1008-选数
已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n)。从 n 个整数中任选 k 个整数相加,可分别得到一系列的和。例如当 n=4,k=3,4 个整数分别为 3,7,12,19 时,可得全部的组合与它们的和为: 3+7+12=22 3+7+19=29 7+12+19=38 3+12+19=34。 现在,要求你计算出和为素数共有多少种。 例如上例,只有一种的和原创 2014-05-16 20:16:33 · 600 阅读 · 0 评论 -
*【Wikioi】1983-等式问题
#include //1 2 3 4 5 6 7 8 9=Nusing namespace std;int ans = 0,N;void dfs(int dep , int sum){ int tmp = 0; if(sum == N && dep>9) { ans++; } else for(int i = dep ; i <=原创 2014-08-13 17:44:44 · 1013 阅读 · 1 评论 -
【Wikioi】1294全排列
做了zhedao#include #include using namespace std;#define MAXN 10int N;int history[MAXN];bool visit[MAXN];vector >ans;vectorline;void dfs(int i){ int j, k; if (i == N) { f原创 2014-08-12 16:12:01 · 525 阅读 · 0 评论 -
【wikioi】2956-排队问题
有N个学生去食堂,可教官规定:必须2人或3人组成一组,求有多少种不同分组的方法。方法1:dp(和pa),公式#include using namespace std;long long ans=0;long long temp_sum=0;long long dp(int n){ long long f[151]= {0}; f[2]=f[3]=1;原创 2014-08-13 16:41:19 · 779 阅读 · 0 评论 -
【CC150-8.2】走格子路径
DFS其实是很灵活的,虽然我习惯按照void d#include #include using namespace std;typedef struct point{ int x, y;} point;const int MAXN = 20;int g[MAXN][MAXN];point vp[MAXN+MAXN];vector pvec;void pr原创 2014-08-12 16:52:09 · 656 阅读 · 0 评论 -
素数环
这#include #include using namespace std;//6//143256//165234bool isPrime(int x){ if(x==1) return false; for(int i=2; i<=sqrt(x); i++) { if(x%i==0) retur原创 2014-08-12 16:57:22 · 598 阅读 · 0 评论 -
【Wikioi】1116四色问题
#include #include #define MAXN 8int N;int g[MAXN][MAXN];int history[MAXN];int count;void dfs2(int i){ if (i == N) { count++; } else for (int color = 1; color < 5; colo原创 2014-08-13 11:22:28 · 881 阅读 · 0 评论 -
【leetcode】Subsets
#include #include #include using namespace std;vector > ans;int len;void dfs(int dep, vector line, vector num){ ans.push_back(line); if(dep == len) { return;原创 2014-08-13 21:11:08 · 478 阅读 · 0 评论 -
【Wikioi】1065-01字符串
输出仅有0和1组成的长度为n的字符串,并且其中不能含有3个连续的相同子串。简单的方法是原创 2014-08-13 13:33:40 · 844 阅读 · 1 评论 -
8.8-N皇后
#include using namespace std;int n=8;int tot=0;int col[8];void dfs(int cur){ if(cur==n) tot++; else for(int i=0; i<n; i++) { int ok=1; col[cur]=i原创 2014-09-08 09:21:13 · 688 阅读 · 0 评论 -
8连块
题目:输入一个n*n的黑白图像(1表示黑色,0表示白色),任务是统计其中八连块的个数。如果两个黑格子有公共边或者公共顶点,就说它们属于同一个八连块。输入:第一行输入一个整数n(n输出:输出有多少个八连块,以及每个块的面积。一个方格的面积为1。分析:把图片最外层扩展开来,在最外面加一层白色的框框。。设置一个数组来存储每个八连块的面积。。DFS递归调用每一个黑色的方转载 2014-09-24 01:31:03 · 883 阅读 · 0 评论