copycat69's blog

By copycat69, history, 13 months ago, In English

I was solving Sum of All Subset XOR Totals on Leetcode. It was obviously a Backtracking problem so I solved it in n*(2^n) . But it surprisingly has a linear solution. Like this

class Solution {
public:
    int subsetXORSum(vector<int>& nums) {
        int sum=0;
        for(auto i:nums)sum|=i;
        return sum*(1<<(nums.size()-1));
    }
};

Why this works ? Does anyone have the proof??

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it

By copycat69, history, 16 months ago, In English

I'm learning DP . Most of the code I've seen so far uses iterative DP. Is there anyone who uses Recursive DP?????

Full text and comments »

  • Vote: I like it
  • +16
  • Vote: I do not like it