Wednesday, June 22, 2016

UVA 729 - The Hamming Distance Problem

Problem Link:
[http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=670]

Catagory: Backtracking,Permutation,Bruteforce.

I took simple approach. First ,write string according to the number of bit and hamming bit. Then generate permuted values of it.

Code:

 #include <bits/stdc++.h>
#define ll  long long int
#define M   10000
using namespace std;

int main()
{    int n,h,t;
       cin>>t;

      while(t--)
         {string a;

   cin>>n>>h;
  for(int i=0;i<n; i++)
      {        if(i<n-h)
            a.push_back('0');

     else
      a.push_back('1');}

     do
     {
           cout<<a<<endl;


     }while(next_permutation(a.begin(),a.end()));
     a.clear();
  if(t)cout<<"\n";
     }

}

No comments:

Post a Comment