HDU 4686 Arc of Dream(矩阵)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686
题意:
思路:
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <ctype.h>
#include <time.h>
#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define CLR(x) x.clear()
#define ph(x) push(x)
#define pb(x) push_back(x)
#define Len(x) x.length()
#define SZ(x) x.size()
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define MP(x,y) make_pair(x,y)
#define EPS 1e-25
#define FOR0(i,x) for(i=0;i<x;i++)
#define FOR1(i,x) for(i=1;i<=x;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FORL0(i,a) for(i=a;i>=0;i--)
#define FORL1(i,a) for(i=a;i>=1;i--)
#define FORL(i,a,b)for(i=a;i>=b;i--)
#define rush() int CC;for(scanf("%d",&CC);CC--;)
#define Rush(n) while(scanf("%d",&n)!=-1)
using namespace std;
void RD(int &x){scanf("%d",&x);}
void RD(i64 &x){scanf("%I64d",&x);}
void RD(u64 &x){scanf("%I64u",&x);}
void RD(u32 &x){scanf("%u",&x);}
void RD(double &x){scanf("%lf",&x);}
void RD(int &x,int &y){scanf("%d%d",&x,&y);}
void RD(i64 &x,i64 &y){scanf("%lld%lld",&x,&y);}
void RD(u32 &x,u32 &y){scanf("%u%u",&x,&y);}
void RD(double &x,double &y){scanf("%lf%lf",&x,&y);}
void RD(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}
void RD(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void RD(i64 &x,i64 &y,i64 &z){scanf("%I64d%I64d%I64d",&x,&y,&z);}
void RD(u32 &x,u32 &y,u32 &z){scanf("%u%u%u",&x,&y,&z);}
void RD(char &x){x=getchar();}
void RD(char *s){scanf("%s",s);}
void RD(string &s){cin>>s;}
void PR(int x) {printf("%d\n",x);}
void PR(int x,int y) {printf("%d %d\n",x,y);}
void PR(i64 x) {printf("%I64d\n",x);}
void PR(i64 x,i64 y) {printf("%lld %lld\n",x,y);}
void PR(u32 x) {printf("%u\n",x);}
void PR(u64 x) {printf("%llu\n",x);}
void PR(double x) {printf("%.10lf\n",x);}
void PR(double x,double y) {printf("%.5lf %.5lf\n",x,y);}
void PR(char x) {printf("%c\n",x);}
void PR(char *x) {printf("%s\n",x);}
void PR(string x) {cout<<x<<endl;}
void upMin(int &x,int y) {if(x>y) x=y;}
void upMin(i64 &x,i64 y) {if(x>y) x=y;}
void upMin(double &x,double y) {if(x>y) x=y;}
void upMax(int &x,int y) {if(x<y) x=y;}
void upMax(i64 &x,i64 y) {if(x<y) x=y;}
void upMax(double &x,double y) {if(x<y) x=y;}
const int mod=1000000007;
const i64 inf=((i64)1)<<60;
const double dinf=1e12;
const int INF=1000000001;
const int N=1005;
i64 n;
i64 f0,a,b;
i64 g0,c,d;
struct Matrix
{
i64 a[5][5];
void init(int x)
{
clr(a,0);
int i;
if(x) FOR0(i,5) a[i][i]=1;
}
Matrix operator*(Matrix p)
{
Matrix ans;
ans.init(0);
int i,j,k;
FOR0(k,5) FOR0(i,5) FOR0(j,5)
{
ans.a[i][j]+=a[i][k]*p.a[k][j]%mod;
ans.a[i][j]%=mod;
}
return ans;
}
Matrix Pow(i64 n)
{
Matrix p=*this,ans;
ans.init(1);
while(n)
{
if(n&1) ans=ans*p;
p=p*p;
n>>=1;
}
return ans;
}
};
Matrix p;
void init()
{
a%=mod; b%=mod; c%=mod; d%=mod;
p.init(0);
p.a[0][0]=1; p.a[0][1]=b; p.a[0][2]=d; p.a[0][3]=b*d%mod; p.a[0][4]=b*d%mod;
p.a[1][1]=a; p.a[1][3]=a*d%mod; p.a[1][4]=a*d%mod;
p.a[2][2]=c; p.a[2][3]=b*c%mod; p.a[2][4]=b*c%mod;
p.a[3][3]=a*c%mod; p.a[3][4]=a*c%mod;
p.a[4][4]=1;
}
int main()
{
while(scanf("%I64d",&n)!=-1)
{
RD(f0,a,b); RD(g0,c,d); f0%=mod; g0%=mod;
if(n==0)
{
puts("0");
continue;
}
i64 ans=0;
init();
p=p.Pow(n-1);
ans+=p.a[0][4]; ans%=mod;
ans+=f0*p.a[1][4]; ans%=mod;
ans+=g0*p.a[2][4]; ans%=mod;
ans+=f0*g0%mod*p.a[3][4]%mod; ans%=mod;
ans+=f0*g0%mod*p.a[4][4]%mod; ans%=mod;
PR(ans);
}
}
HDU 4686 Arc of Dream(矩阵)的更多相关文章
- HDU 4686 Arc of Dream(矩阵)
Arc of Dream [题目链接]Arc of Dream [题目类型]矩阵 &题解: 这题你做的复杂与否很大取决于你建的矩阵是什么样的,膜一发kuangbin大神的矩阵: 还有几个坑点: ...
- hdu 4686 Arc of Dream(矩阵快速幂)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 其中a0 = A0ai = ai-1*AX+AYb0 = B0bi = bi-1*BX+BY ...
- HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...
- hdu 4686 Arc of Dream(矩阵快速幂乘法)
Problem Description An Arc of Dream is a curve defined by following function: where a0 = A0 ai = ai- ...
- HDU 4686 Arc of Dream(递归矩阵加速)
标题效果:你就是给你一程了两个递推公式公式,第一个让你找到n结果项目. 注意需要占用该公式的复发和再构造矩阵. Arc of Dream Time Limit: 2000/2000 MS (Java/ ...
- HDU 4686 Arc of Dream (2013多校9 1001 题,矩阵)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4686 Arc of Dream (矩阵快速幂)
Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDOJ 4686 Arc of Dream 矩阵高速幂
矩阵高速幂: 依据关系够建矩阵 , 高速幂解决. Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/ ...
- HDU 4686 Arc of Dream(快速幂矩阵)
题目链接 再水一发,构造啊,初始化啊...wa很多次啊.. #include <cstring> #include <cstdio> #include <string&g ...
随机推荐
- 从零开始学ios开发(六):IOS控件(3),Segmented Control、Switch
这次的学习还是基于上一个项目继续进行(你也可以新建一个项目)学习Segmented Control和Switch. Segmented Control Switch Segmented Control ...
- Install mcrypt for php on Mac OSX 10.10 Yosemite for a Development Server
mcrypt is a file encryption method using secure techniques to exchange data. It is required for some ...
- iOS 进阶 第九天(0408)
0408 makekeyAndVisible解释 一个程序可以有多个Window,但只有一个窗口能够成为主窗口.如图中所示,此时的window2是主窗口.主窗口用处大了.从iOS7开始无论是主窗口还是 ...
- 【BZOJ 1068】[SCOI2007]压缩
Description 给 一个由小写字母组成的字符串,我们可以用一种简单的方法来压缩其中的重复信息.压缩后的字符串除了小写字母外还可以(但不必)包含大写字母R与M,其中M 标记重复串的开始,R重复从 ...
- cocos3.2中如何创建一个场景
1.可以将一些比较通用的东西放到Common.h中,这是一个.h文件,必须手动添加,且保证在classes目录里 #ifndef __COMMON_H__ #define __COMMON_H__ # ...
- Jenkins入门-转
reference : http://www.cnblogs.com/itech/archive/2011/11/23/2260009.html 在网上貌似没有找到Jenkins的中文的太多的文档,有 ...
- Codeforces Round #321 (Div. 2) D. Kefa and Dishes 状压dp
题目链接: 题目 D. Kefa and Dishes time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 W ...
- Educational Codeforces Round 13 E. Another Sith Tournament 概率dp+状压
题目链接: 题目 E. Another Sith Tournament time limit per test2.5 seconds memory limit per test256 megabyte ...
- PHP读取xml之cdata讲解
实例: xss.xml <?xml version="1.0" encoding="UTF-8"?><filters> <f ...
- HDU 1102 Constructing Roads(最小生成树,基础题)
注意标号要减一才为下标,还有已建设的路长可置为0 题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<str ...