uva - 729 - The Hamming Distance Problem
2014-01-23 17:24
429 查看
题目大意:
输入两个数H、N,H表示一个字符串的长度,该字符串由0,1组成,按字典序输出字符串包含N个1时候的各个组合。
输入两个数H、N,H表示一个字符串的长度,该字符串由0,1组成,按字典序输出字符串包含N个1时候的各个组合。
#define Local #include <iostream> #include <iomanip> #include <string> #include <cstring> #include <cstdio> #include <queue> #include <stack> #include <algorithm> #include <cmath> using namespace std; #define MAX 20 int H, N; void print_binary (int n) { int i = 0; int bin[MAX]; memset(bin, 0, sizeof(bin)); while(n) { bin[i++] = n % 2; n /= 2; } for (i = H-1; i >= 0; i--) cout << bin[i]; cout << endl; } int main() { #ifdef Local freopen("a.in", "r", stdin); freopen("a.out", "w", stdout); #endif int t = 0, max = 0, i = 0, j = 0; cin >> t; while (t--) { cin >> H >> N; max = pow(2, H)-1; for (i = 0; i <= max; i++) { int temp = i, num = 0; while (temp) { temp &= (temp-1); num++; } if (N == num) { print_binary(i); } } if (t) cout << endl; } }
相关文章推荐
- UVa729 - 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(Hamming距离问题)
- UVA 729 The Hamming Distance Problem
- UVa729 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(全排列)
- 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
- UVA - 729 The Hamming Distance Problem
- UVa 729: The Hamming Distance Problem
- uva729 The Hamming Distance Problem