729 - The Hamming Distance Problem(可重集排列,直接枚举)
来源:互联网 发布:上海地区大学 知乎 编辑:程序博客网 时间:2024/06/15 18:36
题目:729 - The Hamming Distance Problem
题目大意:给出字符串的长度,给出要求出现的1的个数,打印出所有的可能的排列,按照递增的顺序,这个字符串只有01组成。
解题思路:这题的思路也是生成可重集排列的思路,只是这里只有0,1,并且个数确定,所以在要进行递归的时候要进行判断。下一个要填0 的时候需要判断一下0的现有个数,1的也一样。如果现有的0(1)的个数小于要求的个数,就说明当前0(1)还可用就递归。
#include<stdio.h>const int N = 20;int s[N], n, h, t;void build(int cur, int * A) {int i, j;if(cur != n) {for( i = 0; i < 2; i++){int c1 = 0;for(j = 0; j < cur; j++)if(A[j] == 0)c1++;if((c1 < n - h && !i) || (cur - c1 < h && i)) {A[cur] = i;build(cur + 1, A);}}}else {for(i = 0; i < n; i++)printf("%d", A[i]);printf("\n");}}int main() {scanf("%d", &t);while(t--){scanf("%d%d", &n, &h);int A[N];build(0, A);if(t)printf("\n");}return 0;}
0 0
- 729 - The Hamming Distance Problem(可重集排列,直接枚举)
- UVA - 729 - The Hamming Distance Problem (枚举排列)
- uva 729 - The Hamming Distance Problem 枚举排列
- uva 729 - The Hamming Distance Problem(全排列)
- UVA - 729 The Hamming Distance Problem (全排列)
- uva-729 - The Hamming Distance Problem-全排列
- UVa729 - The Hamming Distance Problem(全排列)
- 729--The Hamming Distance Problem
- 729 - The Hamming Distance Problem
- 729 - The Hamming Distance Problem
- 729 - The Hamming Distance Problem
- UVa 729 The Hamming Distance Problem
- UVaOJ 729 - The Hamming Distance Problem
- UVa 729 - The Hamming Distance Problem
- UVA 729 - The Hamming Distance Problem
- UVa 729 - The Hamming Distance Problem
- uva 729 - The Hamming Distance Problem
- uva 729 The Hamming Distance Problem
- copy的
- C#,由委托到Observer设计模式,再到事件机制
- 崔永元:中国转基因滥种最厉害 两会上会出示证据
- POJ 2002 Squares 几何 + 二分搜索 或 hash
- ReactiveCocoa (2) map,filter,fold
- 729 - The Hamming Distance Problem(可重集排列,直接枚举)
- Hyperic-Sigar简介
- getchar如何输入输出三位数字问题
- iOS ViewController的生命周期及其加载View的步骤
- spring 事物学习
- 黑马程序员 Java基础学习笔记 线程间同信
- eclipse导入工程中文乱码问题
- HDU 3631 Shortest Path
- ubuntu错误解决E: Sub-process /usr/bin/dpkg returned an error code (1)