No you dun count words using r*nCr, each word has different length
You count total character used by a word by length*appearance
r*nCr is for comma between words
因為可以一題分到candidate係唔識programming 定係識programming但唔識maths 定係又識pgrogramming又識少少applied linear algebra 定係又識programming又識少少difference equation
腦若傷殘2020-05-15 12:23:02
比多幾級你升,等你加多幾次人工,仲唔跪謝腦細
手一黏便緊(UTC+92020-05-15 12:23:52
一級加五百
找數2020-05-15 12:29:21
講明係垃圾
Code4Food2020-05-15 12:43:30
sorry, but that one is also simple:
nCr = nC(n-r)
sum_{r = 0 .. n} r * nCr
= sum_{r= 0...n} (n-r) * nC(n-r) // sum in reverse order
=sum_{r = 0..n} (n-r) * nCr // nCr = nC(n-r)
2 * sum_{r = 0..n} r * nCr
= sum_{r=0..n} r * nCr + sum_r{r=0..n} (n-r)*nCr
= sum_{r=0..n} (r + n-r) * nCr
= n * sum{r=0..n} nCr
= n * 2^n
so sum{0..n} nCr = n/2 * 2^n
Intuitively, every subset of an n-element set correspond to an integer in [0..2^n] such that the i-th element is in the subset if the bit i is set. So we are really counting the number of set bits from [0..2^n]. Well, there are n * 2^n bits total (either 0 or 1) by symmetry only half of the bits are set so the number of 1's is n/2 * 2^n.