Sunday, June 7, 2015

UVa - 729 - The Hamming Distance Problem

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector <int> Ham;
  5. int n;
  6.  
  7. int main(){
  8.     int t, p, f = 0, bl = 0;
  9.     scanf("%d"&t);
  10.     while(t--){
  11.         scanf("%d %d"&n, &p);
  12.         int b = n-p;
  13.         while(p--)Ham.push_back(1);
  14.         while(b--)Ham.push_back(0);
  15.         reverse(Ham.begin(), Ham.end());
  16.         if(bl)puts(""); bl = 1;
  17.         for(int i = 0; i < n; i++)cout << Ham[i];
  18.         puts("");
  19.         while(next_permutation(Ham.begin(), Ham.end())){
  20.             for(int i = 0; i < n; i++)cout << Ham[i];
  21.             puts("");
  22.         }
  23.         Ham.clear();
  24.     }
  25.     return 0;
  26. }

No comments:

Post a Comment