题解 P2000 【拯救世界】

· · 题解

生成函数裸题。

把所有情况罗列出来:

kkk:

金: 1+x^6+x^{12}+\dots=\frac{1}{1-x^6}

木: 1+x+x^2+\dots+x^9=\frac{1-x^{10}}{1-x}

水块: 1+x+x^2+\dots+x^5=\frac{1-x^6}{1-x}

火: 1+x^4+x^8+\dots=\frac{1}{1-x^4}

土: 1+x+x^2+\dots+x^7=\frac{1-x^8}{1-x}

lzn:

金: 1+x^2+x^4+\dots=\frac{1}{1-x^2}

木: 1+x=\frac{1-x^2}{1-x}

水: 1+x^8+x^{16}+\dots=\frac{1}{1-x^8}

火: 1+x^{10}+x^{20}+\dots=\frac{1}{1-x^{10}}

土: 1+x+x^2+x^3=\frac{1-x^4}{1-x}

凉心出题人友好的卡了精度并且顺便卡了pypy。所以,人生苦短,Ruby用我

n = gets.to_i
print (n + 1) * (n + 2) * (n + 3) * (n + 4) / 24