题面太丑了,就不复制了。

题意:F1=A; F2=B; Fn=D*Fn-1+C*Fn-2+P/i;求Fn。

思路:根据P/i的值划分区间,每个区间矩阵求。

带常数的矩阵:

  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define rep(i,a,b) for(int i=a;i<=b;i++)
  4. using namespace std;
  5. const int Mod=1e9+;
  6. struct mat
  7. {
  8. int mp[][];
  9. mat(){memset(mp,,sizeof(mp)); }
  10. mat friend operator *(mat a,mat b)
  11. {
  12. mat res;
  13. rep(k,,) rep(i,,) rep(j,,)
  14. res.mp[i][j]=(res.mp[i][j]+((ll)a.mp[i][k]*b.mp[k][j]%Mod))%Mod;
  15. return res;
  16. }
  17. mat friend operator ^(mat a,int x)
  18. {
  19. mat res;
  20. rep(i,,) res.mp[i][i]=;
  21. while(x){
  22. if(x&) res=res*a; a=a*a; x>>=;
  23. }return res;
  24. }
  25. };
  26.  
  27. int main()
  28. {
  29. int T,N,A,B,C,D,P,fcy;
  30. scanf("%d",&T);
  31. while(T--){
  32. scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&P,&N);
  33. if(N==) {printf("%d",A); continue;}
  34. if(N==) {printf("%d",B); continue;}
  35. for(int i=,r;i<=N;i=r+){
  36. int tmp=P/i;
  37. if(tmp==) r=N;
  38. else r=min(P/(P/i),N);
  39. mat ans,base;
  40. ans.mp[][]=B;ans.mp[][]=A; ans.mp[][]=;
  41. base.mp[][]=D; base.mp[][]=C; base.mp[][]=tmp;
  42. base.mp[][]=base.mp[][]=;
  43. ans=(base^(r-i+))*ans;
  44. if(r==N) fcy=ans.mp[][];
  45. else B=ans.mp[][],A=ans.mp[][];
  46. }
  47. printf("%d\n",fcy);
  48. }
  49. return ;
  50. }

HDU - 6395:Sequence (分块+矩阵)的更多相关文章

  1. HDU 6395 Sequence 【矩阵快速幂 && 暴力】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others)   ...

  2. HDU - 6395 Sequence (分块+快速矩阵幂)

    给定递推式: 求Fn. 分析:给出的公式可以用快速矩阵幂运算得到,但 P/n 整除对于不同的i,值是不同的. 可以根据P将3-n分成若干块,每块中P整除n的值是相同的.分块的时候要注意判断. 将每块的 ...

  3. HDU - 6395 Sequence (整除分块+矩阵快速幂)

    定义数列: $\left\{\begin{eqnarray*} F_1 &=& A \\ F_2 &=& B \\ F_n &=& C\cdot{}F_ ...

  4. HDU 6395 Sequence(分段矩阵快速幂)题解

    题意: 已知\(A,B,C,D,P,n\)以及 \[\left\{ \begin{aligned} & F_1 = A \\ & F_2 = B\\ & F_n = C*F_{ ...

  5. [hdu-6395]Sequence 分块+矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6395 因为题目数据范围太大,又存在递推关系,用矩阵快速幂来加快递推. 每一项递推时  加的下取整的数随 ...

  6. HDU 5667 Sequence(矩阵快速幂)

    Problem Description Holion August will eat every thing he has found. Now there are many foods,but he ...

  7. HDU 5667 Sequence【矩阵快速幂+费马小定理】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5667 题意: Lcomyn 是个很厉害的选手,除了喜欢写17kb+的代码题,偶尔还会写数学题.他找到 ...

  8. HDU 6395 Sequence 杜教板子题

    题目意思非常明确,就是叫你求第n项,据我们学校一个大佬说他推出了矩阵,但是我是菜鸡,那么肯定是用简单的方法水过啦!我们先p^(1/2)的复杂度处理出i=[i,p]范围内的所有种类的(int)(p/i) ...

  9. hdu 6395 Sequence (简单矩乘)

    P/n大多数情况是不变的, 取值只有$O(\sqrt{P})$种, 可以用$p/(p/i)$跳过重复的值, 复杂度$O(logn\sqrt{P})$ 要注意 P跟模数P有冲突 要特判p/i==0和p/ ...

  10. Sequence( 分块+矩阵快速幂 )

    题目链接 #include<bits/stdc++.h> using namespace std; #define e exp(1) #define pi acos(-1) #define ...

随机推荐

  1. webform中Repeater的Command用法、Repeater的替代方法

    Command: 在Repeater控件循环执行过程中,可以给每一项的某个按钮或其他控件设置CommandName.CommandArgument属性,用于在后台代码中获取单项 数据进行调用.   需 ...

  2. Web开发相关笔记

    1.MySQL命令行下执行.sql脚本详解http://database.51cto.com/art/201107/277687.htm 在可视化工具里导出.sql脚本 --> 放命令行里运行 ...

  3. 配置OpenVpn使用证书和用户名密码双验证

    修改OpenVpn的主配置文件 添加一下内容: [root@check1 openvpn]# tail -3 server.conf auth-user-pass-verify /etc/openvp ...

  4. Spring_事务准备

  5. nginx反向代理服务器端口问题

      nginx可以很方便的配置成反向代理服务器 server { listen 80; server_name bothlog.com; location / { proxy_set_header H ...

  6. LeetCode——Construct the Rectangle

    LeetCode--Construct the Rectangle Question For a web developer, it is very important to know how to ...

  7. 低版本C++ string的万能转换,从long string 之间的转换来看看

    string 转 long 那必须是万年atoi(),不过得配合c_str()使用! [plain] view plain copy #include <string> #include  ...

  8. QTableWidget 列排序

    connect(uirecord.tableWidget->horizontalHeader(),SIGNAL(sectionClicked(int)),this,SLOT(record_sor ...

  9. JavaWeb -- Struts1 使用示例: 表单校验 防表单重复提交 表单数据封装到实体

    1. struts 工作流程图 超链接 2. 入门案例 struts入门案例: 1.写一个注册页面,把请求交给 struts处理 <form action="${pageContext ...

  10. Codeforces Round #363 (Div. 2) A、B、C

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...