fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std ;
  4.  
  5. int main()
  6.  
  7. {
  8. int n , k , j , d = 0 , i , m=0 ;
  9. string s="";
  10. string a[1000000];
  11. cin >> k >> n ;
  12.  
  13. for( i = 0 ; i < k ; i++)
  14. s+='0';
  15.  
  16. // cout << s << endl ;
  17. a[m] = s ;
  18.  
  19.  
  20.  
  21. while( m <= n )
  22. {
  23. int i = k-1 ;
  24. while (s[i]=='1' && i > 0)
  25. i--;
  26.  
  27. s[i] = '1';
  28. for (int j = i + 1 ; j < k ; j++)
  29. s[j] = '0';
  30. // cout << s << endl ;
  31. m++;
  32. a[m] = s ;
  33.  
  34.  
  35. }
  36.  
  37. for ( j = 0 ; j < n ; j++ )
  38. { for( i = 0 ; i < k ; i++)
  39. if(a[j][i] != a[j+1][i])
  40. d++ ;
  41. // cout << d <<endl;
  42. // d=0 ;
  43. // cout << a[i] << endl ;
  44. }
  45. // cout << a[i] << endl ;
  46. cout << d ;
  47.  
  48. }
Success #stdin #stdout 0s 47176KB
stdin
3 4
stdout
7