题解

小迪的blog : https://www.cnblogs.com/RabbitHu/p/9178645.html

请大家点推荐并在sigongzi的评论下面点支持谢谢!

掌握了小迪生成函数的有趣姿势之后,我们考虑一下这个问题

由于出题人语死早,我们认为是十种石头的生成函数直接乘起来

\(\frac{1}{1 - x^6} \cdot \frac{1 - x^{10}}{1 - x} \cdot \frac{1 - x^{5}}{1 - x} \cdot \frac{1}{1 - x^4} \cdot \frac{1 - x^8}{1 - x} \cdot \frac{1}{1 - x^2} \cdot \frac{1 - x^2}{1 - x} \cdot \frac{1}{1 - x^8} \cdot \frac{1}{1 - x^10} \cdot \frac{1 - x^4}{1 - x} = \frac{1}{(1 - x)^5}\)

这个正好是上面那个blog里和组合数有关的生成函数,所以我们要求的值就是

\(\binom{n + 5 - 1}{5 - 1} = \binom{n + 4}{4} = \frac{(n + 1)(n + 2)(n + 3)(n + 4)}{24}\)

显然需要高精度了,还得是FFT

可以用NTT代替(因为值不会太大)

“我司嘉祺就算是TLE死,死外面,从这里跳下去,也绝对不会开O2的!”

“氧气真好吸。”

代码

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <vector>
  6. #define enter putchar('\n')
  7. #define space putchar(' ')
  8. #define MAXN 1000005
  9. //#define ivorysi
  10. #define pb push_back
  11. using namespace std;
  12. typedef long long int64;
  13. template<class T>
  14. void read(T &res) {
  15. res = 0;char c = getchar();T f = 1;
  16. while(c < '0' || c > '9') {
  17. if(c == '-') f = -1;
  18. c = getchar();
  19. }
  20. while(c >= '0' && c <= '9') {
  21. res = res * 10 - '0' + c;
  22. c = getchar();
  23. }
  24. res = res * f;
  25. }
  26. template<class T>
  27. void out(T x) {
  28. if(x < 0) {x = -x;putchar('-');}
  29. if(x >= 10) out(x / 10);
  30. putchar('0' + x % 10);
  31. }
  32. const int MOD = 998244353,MaxL = (1 << 20);
  33. int W[(1 << 20) + 5],N;
  34. char a[1000005];
  35. int inc(int a,int b) {
  36. return a + b >= MOD ? a + b - MOD : a + b;
  37. }
  38. int mul(int a,int b) {
  39. return 1LL * a * b % MOD;
  40. }
  41. int fpow(int x,int c) {
  42. int res = 1,t = x;
  43. while(c) {
  44. if(c & 1) res = mul(res,t);
  45. t = mul(t,t);
  46. c >>= 1;
  47. }
  48. return res;
  49. }
  50. struct Bignum {
  51. vector<int> v;
  52. friend Bignum operator + (const Bignum &a,const int &x) {
  53. Bignum c;c.v.clear();
  54. int g = (a.v[0] + x) / 10;
  55. c.v.pb((a.v[0] + x) % 10);
  56. for(int i = 1 ; i < a.v.size() ; ++i) {
  57. int t = a.v[i] + g;
  58. c.v.pb(t % 10);g = t / 10;
  59. }
  60. if(g) c.v.pb(g);
  61. return c;
  62. }
  63. friend void NTT(Bignum &f,int LEN,int on) {
  64. f.v.resize(LEN);
  65. for(int i = 1 , j = LEN / 2 ; i < LEN - 1 ; ++i) {
  66. if(i < j) swap(f.v[i],f.v[j]);
  67. int k = LEN / 2;
  68. while(j >= k) {
  69. j -= k;
  70. k >>= 1;
  71. }
  72. j += k;
  73. }
  74. for(int h = 2 ; h <= LEN ; h <<= 1) {
  75. int wn = W[(MaxL + on * MaxL / h) % MaxL];
  76. for(int k = 0 ; k < LEN ; k += h) {
  77. int w = 1;
  78. for(int j = k ; j < k + h / 2 ; ++j) {
  79. int u = f.v[j],t = mul(w,f.v[j + h / 2]);
  80. f.v[j] = inc(u,t);
  81. f.v[j + h / 2] = inc(u,MOD - t);
  82. w = mul(w,wn);
  83. }
  84. }
  85. }
  86. if(on == -1) {
  87. int InvL = fpow(LEN,MOD - 2);
  88. for(int i = 0 ; i < LEN ; ++i) f.v[i] = mul(f.v[i],InvL);
  89. }
  90. }
  91. friend Bignum operator * (Bignum a,Bignum b) {
  92. int s = a.v.size() + b.v.size() - 2,t = 1;
  93. while(t <= s) t <<= 1;
  94. NTT(a,t,1);NTT(b,t,1);
  95. Bignum c;c.v.clear();
  96. for(int i = 0 ; i < t ; ++i) c.v.pb(mul(a.v[i],b.v[i]));
  97. NTT(c,t,-1);
  98. int64 x = 0;
  99. for(int i = 0 ; i < t ; ++i) {
  100. x += c.v[i];
  101. c.v[i] = x % 10;
  102. x /= 10;
  103. }
  104. while(x) {
  105. c.v.pb(x % 10);
  106. x /= 10;
  107. }
  108. for(int i = c.v.size() - 1 ; i > 0 ; --i) {
  109. if(c.v[i] == 0) c.v.pop_back();
  110. else break;
  111. }
  112. return c;
  113. }
  114. friend Bignum operator / (const Bignum &a,int k) {
  115. Bignum c;c.v.clear();c.v.resize(a.v.size());
  116. int x = 0;
  117. for(int i = a.v.size() - 1 ; i >= 0 ; --i) {
  118. x = x * 10 + a.v[i];
  119. c.v[i] = x / k;
  120. x %= k;
  121. }
  122. for(int i = a.v.size() - 1 ; i > 0 ; --i) {
  123. if(c.v[i] == 0) c.v.pop_back();
  124. else break;
  125. }
  126. return c;
  127. }
  128. void print() {
  129. for(int i = v.size() - 1 ; i >= 0 ; --i) {
  130. putchar('0' + v[i]);
  131. }
  132. }
  133. }A,B;
  134. void Solve() {
  135. W[0] = 1;W[1] = fpow(3,(MOD - 1) / (1 << 20));
  136. for(int i = 2 ; i < (1 << 20) ; ++i) W[i] = mul(W[i - 1],W[1]);
  137. scanf("%s",a + 1);
  138. N = strlen(a + 1);
  139. A.v.clear();
  140. for(int i = N ; i >= 1 ; --i) A.v.pb(a[i] - '0');
  141. B = ((A + 1) * (A + 2)) * ((A + 3) * (A + 4));
  142. B = B / 24;
  143. B.print();enter;
  144. }
  145. int main() {
  146. #ifdef ivorysi
  147. freopen("f1.in","r",stdin);
  148. #endif
  149. Solve();
  150. }

【洛谷】P2000 拯救世界的更多相关文章

  1. 洛谷P2000 拯救世界(生成函数)

    题面 题目链接 Sol 生成函数入门题 至多为\(k\)就是\(\frac{1-x^{k+1}}{1-x}\) \(k\)的倍数就是\(\frac{1}{1-x^k}\) 化简完了就只剩下一个\(\f ...

  2. [洛谷P2000 拯救世界]

    生成函数版题. 考虑对于这些条件写出\(OGF\) \(1 + x^6 + x^{12} + x^{18}..... = \frac{1}{1 - x^6}\) \(1 + x + x ^ 2 + x ...

  3. 洛谷 P1506 拯救oibh总部

    P1506 拯救oibh总部 题目背景 oibh总部突然被水淹没了!现在需要你的救援…… 题目描述 oibh被突来的洪水淹没了>.<还好oibh总部有在某些重要的地方起一些围墙,用*号表示 ...

  4. luogu P2000 拯救世界

    嘟嘟嘟 题目有点坑,要你求的多少大阵指的是召唤kkk的大阵数 * lzn的大阵数,不是相加. 看到这个限制条件,显然要用生成函数推一推. 比如第一个条件"金神石的块数必须是6的倍数" ...

  5. 洛谷P4823 拯救小矮人 [TJOI2013] 贪心+dp

    正解:贪心+dp 解题报告: 传送门! 我以前好像碰到过这题的说,,,有可能是做过类似的题qwq? 首先考虑这种显然是dp?就f[i][j]:决策到了地i个人,跑了j个的最大高度,不断更新j的上限就得 ...

  6. 洛谷 P1506 拯救oibh总部【DFS/Flood Fill】

    题目背景 oibh总部突然被水淹没了!现在需要你的救援…… 题目描述 oibh被突来的洪水淹没了>.<还好oibh总部有在某些重要的地方起一些围墙,用号表示,而一个封闭的号区域洪水是进不去 ...

  7. luogu P2000 拯救世界 生成函数_麦克劳林展开_python

    模板题. 将所有的多项式按等比数列求和公式将生成函数压缩,相乘后麦克劳林展开即可. Code: n=int(input()) print((n+1)*(n+2)*(n+3)*(n+4)//24)

  8. 【做题笔记】洛谷P1506 拯救oibh总部

    跑一遍染色法,最后判断哪些位置没被染色即可 一些技巧: 为了判断方便,把字符转换成 int 型的数字. 注意边界问题 详细解释见代码 #include <iostream> #includ ...

  9. [题解] Luogu P2000 拯救世界

    生成函数板子题...... 要写高精,还要NTT优化......异常dl 这个并不难想啊...... 一次召唤会涉及到\(10\)个因素,全部写出来,然后乘起来就得到了答案的生成函数,输出\(n\)次 ...

随机推荐

  1. webapi框架搭建-安全机制(二)-身份验证

    webapi框架搭建系列博客 身份验证(authentication)的责任是识别出http请求者的身份,除此之外尽量不要管其它的事.webapi的authentication我用authentica ...

  2. CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds

    https://www.codechef.com/DEC17/problems/VK18 #include<cstdio> #include<iostream> #includ ...

  3. BFS搜索:POJ No 3669 Meteor Shower

    #include <iostream> #include <cstring> #include <queue> #include <cstdio> #i ...

  4. [Luogu 3952] NOIP2017 时间复杂度

    [Luogu 3952] NOIP2017 时间复杂度 一年的时间说长不长,说短,也不短. 一年之内无数次觉得难得可怕的题目,原来也就模拟这么回事儿. #include <cstdio> ...

  5. Mac下crontab定时python任务

    1.新建crontab_file vim输入代码*/ * * * * /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 /Us ...

  6. CSS3 颜色模式

    HSL .test{background-color:hsl(<length>, <percentage>, <percentage>);} 1.length 表示 ...

  7. 监控redis数据库应用状态:python,tornado实现

    公司里最近redis服务器压力越来越大,其大概情况,只能从操作系统层面看,并不详尽,故同事在网上找了一个叫做 redis-live的开源项目,我配合部署了一下,还真有点意思,并解决了其中部分小debu ...

  8. 网摘关于BarCodeControl控件

    简介 BarCodeControl是一个用户制作条形码的控件. MicrosoftBarcodeControl9.0是可以在MicrosoftOfficeAccess窗体和报表中显示条码符号的Acti ...

  9. 【leetcode 简单】 第一百一十题 分发饼干

    假设你是一位很棒的家长,想要给你的孩子们一些小饼干.但是,每个孩子最多只能给一块饼干.对每个孩子 i ,都有一个胃口值 gi ,这是能让孩子们满足胃口的饼干的最小尺寸:并且每块饼干 j ,都有一个尺寸 ...

  10. Dynamic Rankings(动态第k大+树套树)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1112 题目: 思路: 树套树板子题. 代码实现如下: #inclu ...