1. 链接:https://www.nowcoder.com/acm/contest/106/B
  2. 来源:牛客网
  3. 题目描述
  4. Its universally acknowledged that therere innumerable trees in the campus of HUST.
  5. One day Xiao Ming is walking on a straight road and sees many trees line up in the right side. Heights of each tree which is denoted by a non-negative integer from 0 to 9 can form a tree string. It's very surprising to find that the tree string can be represent as an initial string repeating K times. Now he wants to remove some trees to make the rest of the tree string looks beautiful. A string is beautiful if and only if the integer it represents is divisible by five. Now he wonders how many ways there are that he could make it.
  6. Note that when we transfer the string to a integer, we ignore the leading zeros. For example, the string “00055” will be seen as 55. And also pay attention that two ways are considered different if the removed trees are different. The result can be very large, so printing the answer (mod 1000000007) is enough. And additionally, Xiao Ming can't cut down all trees.
  7. 输入描述:
  8. The first line contains a single integer K, which indicates that the tree string is the initial string repeating K times.
  9. The second line is the initial string S.
  10. 输出描述:
  11. A single integer, the number of ways to remove trees mod 1000000007.
  12. 示例1
  13. 输入
  14. 1
  15. 100
  16. 输出
  17. 6
  18. 说明
  19. Initially, the sequence is 100’. There are
  20. 6 ways:
  21. 100
  22. 1_0
  23. 10_
  24. _00
  25. __0
  26. _0_
  27. 示例2
  28. 输入
  29. 3
  30. 125390
  31. 输出
  32. 149796

【出处】:CF 327 C

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <queue>
  5. #include <stack>
  6. #include <set>
  7. #include <string>
  8. #include <cstdlib>
  9. #include <cmath>
  10. using namespace std;
  11. #define ll long long
  12. #define mod 1000000007
  13. ll Pow(ll a, ll b)
  14. {
  15. ll res=1;
  16. while(b)
  17. {
  18. if(b&1)
  19. res=res*a%mod;
  20. a=a*a%mod;
  21. b>>=1;
  22. }
  23. return res;
  24. }
  25. int main()
  26. {
  27. string s;int k;
  28. while(cin>>k>>s)
  29. {
  30. ll ans=0;
  31. ll n=s.size();
  32. for(int i=0;i<n;i++)
  33. if(s[i]=='0' || s[i]=='5')
  34. ans += Pow(2,i); //原串
  35. ll fm = Pow(2,n);
  36. ll fz = Pow(fm,k);
  37. fz = ((1-fz)%mod+mod)%mod;
  38. fm = ((1-fm)%mod+mod)%mod;
  39. ans = ((ans%mod) * (fz * Pow(fm,mod-2)%mod) ) % mod;
  40. //inv(1-2^n) = pow(1-2^n , mod-2)
  41. printf("%lld\n",ans);
  42. }
  43. return 0;
  44. }

第十四届华中科技大学程序设计竞赛 B Beautiful Trees Cutting【组合数学/费马小定理求逆元/快速幂】的更多相关文章

  1. 第十四届华中科技大学程序设计竞赛 C Professional Manager【并查集删除/虚点】

    题目描述 It's universally acknowledged that there're innumerable trees in the campus of HUST. Thus a pro ...

  2. 第十四届华中科技大学程序设计竞赛决赛同步赛 A - Beauty of Trees

    A - Beauty of Trees 题意: 链接:https://www.nowcoder.com/acm/contest/119/A来源:牛客网 Beauty of Trees 时间限制:C/C ...

  3. 第十四届华中科技大学程序设计竞赛决赛同步赛 F Beautiful Land(01背包,背包体积超大时)

    链接:https://www.nowcoder.com/acm/contest/119/F来源:牛客网 Beautiful Land 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1 ...

  4. 第十四届华中科技大学程序设计竞赛 K Walking in the Forest【二分答案/最小化最大值】

    链接:https://www.nowcoder.com/acm/contest/106/K 来源:牛客网 题目描述 It's universally acknowledged that there'r ...

  5. 第十四届华中科技大学程序设计竞赛 J Various Tree【数值型一维BFS/最小步数】

    链接:https://www.nowcoder.com/acm/contest/106/J 来源:牛客网 题目描述 It's universally acknowledged that there'r ...

  6. 第十四届华中科技大学程序设计竞赛决赛同步赛 Beautiful Land

    It’s universally acknowledged that there’re innumerable trees in the campus of HUST.Now HUST got a b ...

  7. 第十四届华中科技大学程序设计竞赛 K--Walking in the Forest

    链接:https://www.nowcoder.com/acm/contest/106/K来源:牛客网 题目描述 It’s universally acknowledged that there’re ...

  8. 第十四届华中科技大学程序设计竞赛--J Various Tree

    链接:https://www.nowcoder.com/acm/contest/106/J来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  9. Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again

    Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again https://ac.nowcoder.com/acm/contest/700/I 时间限制:C/C++ 1 ...

随机推荐

  1. 《Cracking the Coding Interview》——第2章:链表——题目3

    2014-03-18 02:25 题目:给定一个单链表中间的节点,删掉那个节点. 解法:把后面节点的数据域拷到当前节点来,然后删除后面那个节点.当前节点不是尾巴,所以后面不为空. 代码: // 2.2 ...

  2. Pascal游戏 大富翁MUD

    大富翁MUD Pascal源码 Chaobs改编自百度网友作品 此源码非Chaobs原创,但转载时请仍注明出处. 估计90后以后就没有孩子知道MUD了. program wxtw; uses crt; ...

  3. JMeter学习笔记(五) 文件上传接口测试

    此次测试的是上传图片接口,我把测试情况整理了一下,其他的上传文件接口都类似. 1.我通过jmeter的录制功能获取到了接口地址以及相关参数,如果有接口文档就会方便很多,此步骤就不多做说明了 2.因为上 ...

  4. Pytest 断言

    pytest 断言 断言:一个标准的用例都包含了断言,编写pytest自动化脚本的时候,也需要设置断言 assert使用 常用分三种 1:比较大小与是否相等 2:包含或不包含  3:验证boolean ...

  5. python之urllib.request.urlopen(url)报错urllib.error.HTTPError: HTTP Error 403: Forbidden处理及引申浏览器User Agent处理

    最近在跟着院内大神学习python的过程中,发现使用urllib.request.urlopen(url)请求服务器是报错: 在园子里找原因,发现原因为: 只会收到一个单纯的对于该页面访问的请求,但是 ...

  6. SQLEXPRESS 2012 安装NorthWind和Pub数据库

    安装SQL后,学习时总是没有这两个示例数据库. 先从微软那里下载此文件. 网址:http://www.microsoft.com/en-us/download/details.aspx?id=2365 ...

  7. 【Python】- pytharm 中import时无法识别自己写的程序

    右键点击自己的工作空间,找下面的Mark Directory as(将目录标记为) 选择Source Root,就可以解决上面的问题了,如图

  8. 【Linux】- 获取root权限命令

    1:Redhat系统或者Fedora或者CentOs的Linux发行版,那么在Linux终端输入命令回车: su - root 这样就可以切换到root权限了 2:Ubuntu系统,在Linux终端输 ...

  9. 【R】多元线性回归

    R中的线性回归函数比较简单,就是lm(),比较复杂的是对线性模型的诊断和调整.这里结合Statistical Learning和杜克大学的Data Analysis and Statistical I ...

  10. vs修改快捷键

    https://jingyan.baidu.com/album/9158e0006e10d8a254122826.html?picindex=1 https://sanwen8.cn/p/114IrR ...