Recently one of my friends shared this problem with me. I really found this beautiful and thought of giving it a share.I won't spoil the essence of this problem, but definitely expecting some nice approaches and solutions in the comment.
# | User | Rating |
---|---|---|
1 | jiangly | 3898 |
2 | tourist | 3840 |
3 | orzdevinwang | 3706 |
4 | ksun48 | 3691 |
5 | jqdai0815 | 3682 |
6 | ecnerwala | 3525 |
7 | gamegame | 3477 |
8 | Benq | 3468 |
9 | Ormlis | 3381 |
10 | maroonrk | 3379 |
# | User | Contrib. |
---|---|---|
1 | cry | 168 |
2 | -is-this-fft- | 165 |
3 | Dominater069 | 161 |
4 | atcoder_official | 160 |
5 | Um_nik | 159 |
6 | djm03178 | 157 |
7 | adamant | 153 |
8 | luogu_official | 151 |
9 | awoo | 149 |
10 | TheScrasse | 146 |
Recently one of my friends shared this problem with me. I really found this beautiful and thought of giving it a share.I won't spoil the essence of this problem, but definitely expecting some nice approaches and solutions in the comment.
Name |
---|
Auto comment: topic has been updated by cryo_coder123 (previous revision, new revision, compare).
dp[i] = the longest subsequence from the first i element which has the condition (xor = k) and the last element in the subsequence is arr[i]. then dp[i] = dp[last (arr[i] ^ k)] + 1, and you can save what is the last x.
First if k=0 we can see the answer is the frequency of the element which occurs maximum number of times in the array. Else we can do the following:
First keep track of vector of positions of each element in the array. It is easy to see that the required subsequence must be of the form [x, x^k, x, x^k.....] for some 1<=x<=10^6. So just brute force for each possible value of x and greedily check the subsequence with maximum length we can obtain by using the vector of positions for x and x^k.
Time complexity: O(10^6) + O(n)
Ya did the same thing... have a look at my piece of code