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. 深入理解Netscaler INat

    深入理解Netscaler INat http://blog.51cto.com/caojin/1898173 Netscaler的INat主要是用作基于目的地址的转换,将client访问的公网IP通 ...

  2. BZOJ1044 [HAOI2008]木棍分割 【二分+Dp】

    1044: [HAOI2008]木棍分割 Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 4281  Solved: 1644 [Submit][St ...

  3. HTML5 canvas流体力学效果

    某人用Java搞了一个流体力学的演示:http://grantkot.com/MPM/Liquid.html. 下面是 HTML 5版的流体力学演示(推荐使用Chrome浏览器浏览): 效果演示 &l ...

  4. android OTA升级包制作

    0.签名 java -Xmx2048m -jar out/host/linux-x86/framework/signapk.jar -w build/target/product/security/t ...

  5. HDU 4417 划分树写法

    Problem Description Mario is world-famous plumber. His “burly” figure and amazing jumping ability re ...

  6. 汕头市队赛 C KMP codeforces B. Image Preview

    汕头市队赛题目传送门 codeforces题目传送门 这道题我的做法是 尝试先往左走然后往右走 或者先往右走然后往左走 然后注意一下枚举顺序就okay啦 #include<cstdio> ...

  7. C++类学习

    一.C++类的定义     C++中使用关键字 class 来定义类, 其基本形式如下:class 类名{ public: //行为或属性  protected: //行为或属性 private: / ...

  8. appium的使用

    这套教程年久失修,问题的人也比较多,于是,我重新整理了一套appium入门教程. appium新手入门(1)—— appium介绍 appium新手入门(2)—— 安装 Android SDK app ...

  9. jQuery九宫格图片拉伸变大代码

    之前看到网上有jQuery九宫格图片拉伸变大代码只可以动六张图片,我改了改做了九张图片都可以做的 图片的布局 成品就是每一个图片都可以动看到大图 css样式 <style> /*九宫格*/ ...

  10. 存储过程 ----- navicat 创建存储过程

    以下为navicat 创建存储过程步骤图解: 1. 2. 3. 4. 在存储过程正文中是输入一行语句测试用,点击保存 5.输入存储过程名称,点击确定 6.到这来那么问题来了,会提示错误 7.切记存储过 ...