开发者

Project Euler: please help me understand #106

I have solved #103 and #105, but I have a hard time understanding #106, specifically where does the number 25 come from?

If we are talking about two disjoint subsets with equal number of elements, then

1-elem vs. 1-elem: there are 4 x 3 = 12 comparisons
2 vs. 2: C(4, 2) = 6 comparisons

If we include disjoint subsets wit开发者_StackOverflowh non-equal number of elements, then

1 vs. 2: C(4, 1) x C(3, 2) = 12
1 vs. 3: C(4, 1) = 4

What am I missing here? Thanks in advance.


For the first two types of comparisons, I get half your numbers -- I think a comparison that is just the reverse of another comparison doesn't count as a new one.

For example, if the four elements are a,b,c,d, then the 2 vs 2 comparison a,b vs. c,d is the same as c,d vs. a,b. So I get:

1 vs 1: 6
2 vs 2: 3
1 vs 2: 12
1 vs 3: 4

which does indeed add up to 25.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜