niyaznigmatullin

Untitled

Apr 1st, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. long long f(long long n, int k) {
  2.   ++n;
  3.   vector<int> d;
  4.   while (n > 0) {
  5.     d.push_back(n & 1);
  6.     n >>= 1;
  7.   }
  8.   long long ans = 0;
  9.   for (int i = 0; i < (int) d.size(); i++) {
  10.     if (d[i] == 1) {
  11.       int onesInPrefix = 0;
  12.       for (int j = i + 1; j < (int) d.size(); j++) {
  13.         onesInPrefix += d[j];
  14.       }
  15.       if (onesInPrefix <= k)
  16.         ans += c[i][k - onesInPrefix];
  17.     }
  18.   }
  19.   return ans;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment