Recently I have encountered many questions which require performing some operations like XOR, or some f(x) pairwise on a Set…
by pairwise I mean, if set is {2, 4, 6}
then required O/P is 2^4 + 4^6 + 6^2 or f(2,4) + f(4,6) + f(6,2)
How to handle such questions, someone help…
Also can such questions be solved using DP?
here is the problem i think fit well for your question : SPOJ.com - Problem FRND
i don’t want to post code here , i will recommend you to solve this problem first
(used in codechef lunchtime conetest)
Problem Link->Pairwise AND Sum (CodeChef: Practical coding for everyone)
Editorial Link->(AND - Editorial - editorial - CodeChef Discuss)
Both problems have same concept .
Hope this help.
yeah that was just one of those problems I faced, also there was one where f(x,y) = gcd(x,y)
btw thanx buddy
keep up the good work
1 Like