打印所有匹配括号组合
2011-09-07 14:12
274 查看
char dst[100]; void parentheses_match(char dst[], int k, int left_remain, int left_used, int right_used, int M) { if (right_used >= M) { dst[k] = '\0'; printf("%s\n",dst); return; } if (left_remain <= 0 && left_used < M) { dst[k] = '('; parentheses_match(dst,k+1,left_remain+1,left_used+1,right_used,M); } else if (left_used < M) { dst[k] = '('; parentheses_match(dst,k+1,left_remain+1,left_used+1,right_used,M); dst[k] = ')'; parentheses_match(dst,k+1,left_remain-1,left_used,right_used+1,M); } else { dst[k] = ')'; parentheses_match(dst,k+1,left_remain-1,left_used, right_used+1,M); } } int _tmain(int argc, char* argv[]) { const int M = 10; parentheses_match(dst,0,0,0,0,M); return 0; }
相关文章推荐
- 打印n对括号匹配的所有组合
- LeetCode 22 Generate Parentheses(找到所有匹配的括号组合)
- 打印括号的所有组合
- 9.9递归和动态规划(六)——打印n对括号的所有有效组合(即左右括号正确配对)
- 打印所有括号匹配排列方式
- 打印括号匹配的所有排列
- 打印出所有可能的括号组合
- 打印所有括号匹配排列方式
- 打印包含n个括号的所有合法的组合
- 1:菱形输出星号;2:打印100~999所有的水仙花数;3:求Sn=a+aa+aaa+aaaa+aaaaa的前五项之和;4:从标准输入读取C源代码,验证所有的花括号都是正确的成对出现
- 网新国际2008春季招聘笔试题 打印电话号码所对应的字符的所有可能组合
- 打印n对括号的全部有效组合
- 给定n对括号,编写一个函数来生成正确括号的所有组合。
- 打印n对括号的全部有效组合(即左右括号正确配对)
- UVA1626Brackets sequence(区间DP--括号匹配+递归打印)
- 【搜狐笔试】显示所有正确的括号匹配
- 输出n对括号的所有有效(左右括号成对匹配)排列
- 打印N个真值的所有真值组合
- 打印9!所有组合,并且计算行,列,对角之和为15的矩阵
- POJ1141 Brackets Sequence (最小括号匹配升级版:区间DP+打印路径)