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. [洛谷P1401]城市

    题目大意:有$n(2\leqslant n\leqslant200)$个城市,$m(1\leqslant m\leqslant40000)$条无向边,你要找$T(1\leqslant T\leqsla ...

  2. VK Cup 2016 - Round 1 (Div. 2 Edition) A Bear and Reverse Radewoosh

    A. Bear and Reverse Radewoosh time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  3. auto login vpnclient bat

    @echo offstart "" /b "C:\Program Files (x86)\Cisco Systems\VPN Client\vpngui.exe" ...

  4. CSS3奇偶选择器

    .search-form td:nth-child(odd){//奇 width:100px; text-align:right;} .search-form td:nth-child(even){/ ...

  5. 转:强化学习(Reinforcement Learning)

    机器学习算法大致可以分为三种: 1. 监督学习(如回归,分类) 2. 非监督学习(如聚类,降维) 3. 增强学习 什么是增强学习呢? 增强学习(reinforcementlearning, RL)又叫 ...

  6. C++中的垃圾回收和内存管理

    最开始的时候看到了许式伟的内存管理变革系列,看到性能测试结果的时候,觉得这个实现很不错,没有深入研究其实现.现在想把这个用到自己的一个项目中来,在linux下编译存在一些问题,所以打算深入研究一下. ...

  7. JHDU 2601 An easy problem (数学 )

    title: An easy problem 数学 杭电2601 tags: [数学] 题目链接 Problem Description When Teddy was a child , he was ...

  8. js中typeof 与instanceof的区别

    1.typeof 用来检测给定变量的数据类型,其返回的值是下列某个字符串: "undefined":变量未定义 "boolean":变量为布尔类型 " ...

  9. Django【进阶】权限管理

    一.权限 RBAC:role basic access control   1.什么是权限: 一个权限就是一个url,不同个权限对应不同的url,拥有权限即可以访问这个url.   2.权限划分: 如 ...

  10. 搭建git for windows服务器(100%可以成功)【转】

    转自:http://blog.csdn.net/code_style/article/details/38764203 既然Git在linux下面非常好用,为什么还要搭建git windows的服务器 ...