http://acm.fzu.edu.cn/contest/list.php?cid=152

主要是a题, lucas定理, 就这一版能过..  记录一下代码, 另外两个最短路  一个模拟,没什么记录价值.

  1. //#define txtout
  2. //#define debug
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<algorithm>
  7. #include<queue>
  8. #define mt(a,b) memset(a,b,sizeof(a))
  9. using namespace std;
  10. typedef long long LL;
  11. const double pi=acos(-1.0);
  12. const double eps=1e-;
  13. const int inf=0x3f3f3f3f;
  14. //const int M=1e7+10;
  15.  
  16. LL pow_mod (LL a, LL n, LL p) {
  17. LL ans = ,t = a;
  18. while (n) {
  19. if (n & ) {
  20. ans = ans * t % p;
  21. }
  22. t = t * t % p;
  23. n >>= ;
  24. }
  25. return ans;
  26. }
  27. LL cal (LL n, LL m, LL p) {
  28. if(m > n-m) m = n - m;
  29. LL ans = ;
  30. for (int i = ; i <= m; i++) {
  31. ans = ans * (n - i + ) % p;
  32. int a = pow_mod(i,p-,p);
  33. ans = ans * a % p;
  34. }
  35. return ans;
  36. }
  37. LL com_mod (LL n,LL m,LL p) {
  38. if (n < m)return ;
  39. return cal(n,m,p);
  40. }
  41. LL lucas (LL n, LL m, LL p) {
  42. LL r = ;
  43. while(n && m && r) {
  44. r = r *com_mod(n%p, m%p, p) % p;
  45. n /= p;
  46. m /= p;
  47. }
  48. return r;
  49. }
  50.  
  51. LL a,d,m,n;
  52. //int c[M];
  53. //LL C(int n,int m) {
  54. // LL result=1;
  55. // for(int i=0; i<m; i++) {
  56. // result*=(n-i);
  57. // }
  58. // for(int i=0; i<m; i++) {
  59. // result/=(1+i);
  60. // }
  61. // return result;
  62. //}
  63. const LL MOD=;
  64. LL solve() {
  65. if(n==){
  66. return a;
  67. }
  68. LL answer=lucas(m+n-,n-,MOD)*a%MOD;
  69. if(n->=) answer+=lucas(m+n-,n-,MOD)*d%MOD;
  70. answer%=MOD;
  71. return answer;
  72. }
  73. int main() {
  74. #ifdef txtout
  75. freopen("in.txt","r",stdin);
  76. freopen("out.txt","w",stdout);
  77. #endif // txtout
  78. // num=sieve(MAXN);
  79. while(~scanf("%I64d%I64d%I64d%I64d",&a,&d,&m,&n)) {
  80. printf("%I64d\n",solve());
  81. }
  82. return ;
  83. }

end

FOJ有奖月赛-2016年8月(daxia专场之过四题方有奖)的更多相关文章

  1. FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)

    Problem A Daxia & Wzc's problem Accept: 42    Submit: 228Time Limit: 1000 mSec    Memory Limit : ...

  2. 2016年12月31日 星期六 --出埃及记 Exodus 21:26

    2016年12月31日 星期六 --出埃及记 Exodus 21:26 "If a man hits a manservant or maidservant in the eye and d ...

  3. 2016年12月30日 星期五 --出埃及记 Exodus 21:25

    2016年12月30日 星期五 --出埃及记 Exodus 21:25 burn for burn, wound for wound, bruise for bruise.以烙还烙,以伤还伤,以打还打 ...

  4. 2016年12月29日 星期四 --出埃及记 Exodus 21:24

    2016年12月29日 星期四 --出埃及记 Exodus 21:24 eye for eye, tooth for tooth, hand for hand, foot for foot,以眼还眼, ...

  5. 2016年12月28日 星期三 --出埃及记 Exodus 21:23

    2016年12月28日 星期三 --出埃及记 Exodus 21:23 But if there is serious injury, you are to take life for life,若有 ...

  6. 2016年12月27日 星期二 --出埃及记 Exodus 21:22

    2016年12月27日 星期二 --出埃及记 Exodus 21:22 "If men who are fighting hit a pregnant woman and she gives ...

  7. 2016年2月16日开始,每天一篇,记录学习心得,【基本技能篇】>>开篇《如何阅读一本书——心得》

    如何阅读一本书——心得 ——2016年2月12日 要达到阅读的所有目的,就必须在阅读不同书籍的时候,运用适当的不同速度.读的太快或太慢,都一无所获. 四个阅读层次:①基础阅读,具有基本阅读的能力,包括 ...

  8. Python array,list,dataframe索引切片操作 2016年07月19日——智浪文档

    array,list,dataframe索引切片操作 2016年07月19日——智浪文档 list,一维,二维array,datafrme,loc.iloc.ix的简单探讨 Numpy数组的索引和切片 ...

  9. c++中变量声明和变量定义的区别。2016年12月6日

    整个流程: 1.程序告诉cpu,程序将要使用一个变量.(暂时不一定用到,先说一下.) 2.程序告诉CPU,程序现在就要使用一个变量.(现在就用) 3.cpu按照这个变量的类型,把内存划分出几个单位(b ...

随机推荐

  1. ORA-600 [Kcbz_check_objd_typ_1] Running a Job (Doc ID 785899.1)

    ORA-600 [Kcbz_check_objd_typ_1] Running a Job (Doc ID 785899.1) To Bottom In this Document   Symptom ...

  2. 深入浅出的webpack构建工具---PostCss(五)

    一:PostCss是什么?  PostCss是一个样式处理工具,它通过自定义的插件和工具生态体系来重新定义css.它鼓励开发者使用规范的css原生语法编写代码,然后配置编译器转换需要兼容的浏览器版本, ...

  3. Luogu P1962 斐波那契数列(矩阵乘法模板)

    传送门(其实就是求斐波那契数列....) 累了 明天再解释 做这道题需要一些关于矩阵乘法的基础知识. 1. 矩阵乘法的基础运算 只有当矩阵A的列数等于矩阵B的行数时,A与B可以相乘(A的行数不一定等于 ...

  4. win10 + VS2010 + OpenCV2.4.10重编译OpenCV开发环境搭建

    win10 + VS2010 + OpenCV2.4.10重编译OpenCV开发环境搭建 重编译的优点:能够调试的时候看OpenCV的源码. 重编译要得到的东西:Debug版本号和Release版本号 ...

  5. python3 编程使用技巧

    from random import randint data = {"Student{}".format(i):randint(60,100) for i in range(1, ...

  6. Springboot 2.0.4 整合Mybatis出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

    在使用Springboot 2.0.4 整合Mybatis的时候出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are require ...

  7. python 的zip 函数小例子

    In [57]: name = ('Tome','Rick','Stephon') In [58]: age = (45,23,55) In [59]: for a,n in zip (name,ag ...

  8. python 常见矩阵运算

    python 的 numpy 库提供矩阵运算的功能,因此我们在需要矩阵运算的时候,需要导入 numpy 的包. 1.numpy 的导入和使用 from numpy import *;#导入numpy的 ...

  9. [HAOI2017]方案数[组合计数、容斥、dp]

    题意 题目链接 分析 先考虑没有障碍怎么做,定义 f(i,j,k) 每一维走了 i,j,k 位的方案数,转移乘个组合数即可. 现在多了一些障碍,考虑容斥.实际我们走过的点都有严格的大小关系,所以先把所 ...

  10. for循环两个略骚的写法

    骚写法 或许你知道,总之我觉得很酷,希望你也这么认为. 递增遍历 最常见场景,从 0 到 10 的遍历,不输出 10: for(let i = -1; ++i < 10;) { console. ...