ZOJ 3380 Patchouli's Spell Cards [基础DP+大数]
Description
Patchouli Knowledge, the unmoving great library, is a magician who has settled down in the Scarlet Devil Mansion (紅魔館). Her specialty is elemental magic employing the seven elements fire, water, wood, metal, earth, sun, and moon. So she can cast different spell cards like?Water Sign "Princess Undine",?Moon Sign "Silent Selene"?and?Sun Sign "Royal Flare". In addition, she can combine the elements as well. So she can also cast high-level spell cards like?Metal & Water Sign "Mercury Poison"?and?Fire, Water, Wood, Metal & Earth Sign "Philosopher's Stones"?.
Assume that there are?m?different elements in total, each element has?n?different phase. Patchouli can use many different elements in a single spell card, as long as these elements have the same phases. The level of a spell card is determined by the number of different elements used in it. When Patchouli is going to have a fight, she will choose?m?different elements, each of which will have a random phase with the same probability. What's the probability that she can cast a spell card of which the level is no less than?l, namely a spell card using at least?l?different elements.
題意:
抽象的來說,就是給你M個不同的球,N種顏色,現在給球染色,問至少有L個球同一種顏色的概率。
范圍:
N,M,L<=100
解法:
總方案數很好算,為N^M,剩下的就是求至少L個球同色的方案數,其可以轉換為 (總方案數-每種顏色至多L-1個球的方案數)。
然后就是很明顯的DP了,DP[I][J]表示已放完I種顏色,剩下J個球的方案數,那么轉移方程為
DP[I+1][J-K]+=DP[I][J]*C(J,K) 其中C()為組合數,K為當前顏色裝的球數。
注意會暴longlong,需要用大數,我這里使用了JAVA寫大數
總結
以上是生活随笔為你收集整理的ZOJ 3380 Patchouli's Spell Cards [基础DP+大数]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ghost使用图解加详细说明
- 下一篇: 科普:维基百科与其创始人