Water Problem

Time Limit:3000/1000 MS (Java/Others)   Memory Limit:163840/131072 KB (Java/Others)
Total Submissions:1228   Accepted:121

[Submit][Status][Discuss]

Description

函数 f:Z+→Z

。已知 f(1),f(2) 的值,且对于任意 x>1,有 f(x+1)=f(x)+f(x−1)+sin(πx2)

求 f(n)

的值。

Input

多组数据。(数据组数 T≤100

每组数据包含 3

个不超过 109 的正整数,分别代表 f(1),f(2) 和 n

的值。

Output

输出 f(n)mod(109+7)

。每组输出末尾有换行符。

Sample Input

1 2 3
1 2 5

Sample Output

3
7
【分析】矩阵快速幂裸题。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
#define pb push_back
using namespace std;
typedef long long ll;
const long long mod = 1e9+;
const long long N = ;
ll f1,f2;
int n;
struct Fast_Matrax
{ ll a[N][N];
Fast_Matrax()
{
memset(a,,sizeof(a));
}
void init()
{
for(int i=;i<N;i++)
for(int j=;j<N;j++)
a[i][j]=(i==j);
}
Fast_Matrax operator * (const Fast_Matrax &B)const
{
Fast_Matrax C;
for(int i=;i<N;i++)
for(int k=;k<N;k++)
for(int j=;j<N;j++)
C.a[i][j]=(C.a[i][j]+1LL*a[i][k]*B.a[k][j]%mod+mod)%mod;
return C;
}
Fast_Matrax operator ^ (const int &t)const
{
Fast_Matrax A=(*this),res;
res.init();
int p=t;
while(p)
{
if(p&)res=res*A;
A=A*A;
p>>=;
}
return res;
}
}ans,tmp,x;
int main()
{
while(~scanf("%lld%lld%d",&f1,&f2,&n))
{
x.a[][]=f2;x.a[][]=f1;x.a[][]=,x.a[][]=;
if(n==)printf("%lld\n",f1);
else if(n==)printf("%lld\n",f2);
else
{
tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;
tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;
tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;tmp.a[][]=-;
tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;
ans=x*(tmp^(n-));
printf("%lld\n",ans.a[][]);
}
}
return ;
}
												

dutacm.club Water Problem(矩阵快速幂)的更多相关文章

  1. HDU1757 A Simple Math Problem 矩阵快速幂

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

  3. 焦作网络赛L-Poor God Water【矩阵快速幂】

    God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...

  4. bnuoj 16493 Just Pour the Water(矩阵快速幂)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=16493 [题解]:矩阵快速幂 [code]: #include <cstdlib> #i ...

  5. zoj 2974 Just Pour the Water (矩阵快速幂,简单)

    题目 对于案例的解释请见下图: 这道要变动提取一下矩阵,之后就简单了 具体解释可看代码: #include <string.h> #include <stdio.h> #inc ...

  6. ZOJ 2794 Just Pour the Water 【矩阵快速幂】

    给你n个杯子,每次有特定的到水规则,倒m次请问最后每个被子里还有多少水 我们很容易发现每次变化的规则相同,那么可以set 一个矩阵存放 然后多次倒水就相当于矩阵相乘,在m 范围达到(1<= M  ...

  7. ACM-ICPC 2018 焦作赛区网络预赛 L Poor God Water(矩阵快速幂,BM)

    https://nanti.jisuanke.com/t/31721 题意 有肉,鱼,巧克力三种食物,有几种禁忌,对于连续的三个食物:1.这三个食物不能都相同:2.若三种食物都有的情况,巧克力不能在中 ...

  8. HDU - 3521 An easy Problem(矩阵快速幂)

    http://acm.hdu.edu.cn/showproblem.php?pid=3521 题意 对于矩阵A,求e^A的值. 分析 这个定眼一看好像很熟悉,就是泰勒展开,可惜自己的高数已经还给老师了 ...

  9. A Simple Math Problem(矩阵快速幂)----------------------蓝桥备战系列

    Lele now is thinking about a simple function f(x).  If x < 10 f(x) = x.  If x >= 10 f(x) = a0 ...

随机推荐

  1. GDI绘图中的映射模式CDC::SetMapMode()

    原文链接:http://blog.csdn.net/charlessimonyi/article/details/8264572 在GDI绘图前,一般要设置映射模式.映射模式是什么呢?它是逻辑长度单位 ...

  2. BZOJ3648 寝室管理 【点分治 + 环套树】

    3648: 寝室管理 Time Limit: 40 Sec  Memory Limit: 512 MB Submit: 366  Solved: 152 [Submit][Status][Discus ...

  3. phaser常用API总结

    1. 游戏画布的尺寸 var width = game.width, height = game.height;   2. 中心点坐标 var game = new Phaser.Game(...); ...

  4. @Resource注解完成自动装配

    @Resource注解是通过名字来自动装配的.在spring中自动装配的模式如果是通过名字来自动装配那么必须保证bean的名字和pojo 的属性名一直. 下面是详细代码:说明了@Resource注解是 ...

  5. centos的网络设置问题

    遭遇了多次centos的网络连接问题,现将正确配置总结下: 这里是使用vmware虚拟平台,因为涉及到中间这层,所以需要设置下: 保证centos也能连上网,首先物理机连上网,接着物理机的vmware ...

  6. centos6上使用fpm打python2.7 rpm包并兼容python2.6

    centos6上使用fpm打python2.7 rpm包并兼容python2.6 作者 运维小兵_加油 关注 2016.09.22 00:28 字数 501 阅读 45评论 0喜欢 1 工作中我们常常 ...

  7. python监控服务器

    import paramikoimport threadingimport reimport timeimport stringfrom sendmail import send_maildef ss ...

  8. WEB-INF 有关的目录路径问题总结

    1.资源文件只能放在WebContent下面,如 CSS,JS,image等.放在WEB-INF下引用不了. 2.页面放在WEB-INF目录下面,这样可以限制访问,提高安全性.如JSP,html 3. ...

  9. 【NOIP1999】邮票面值设计 dfs+dp

    题目传送门 这道题其实就是找一波上界比较麻烦 用一波 背包可以推出上界mx 所以新加入的物品价值一旦大于mx+1,显然就会出现断层,所以可以以maxm+1为枚举上界,然后这样进行下一层的dfs. 这样 ...

  10. equestAnimationFrame

    export const requestAnimationFrame = (() => { /* istanbul ignore next */ if (!inBrowser) { return ...