HDU4686

An Arc of Dream is a curve defined by following function:

where
a 0 = A0
a i = a i-1*AX+AY
b 0 = B0
b i = b i-1*BX+BY
What is the value of AoD(N) modulo 1,000,000,007?
Input
There are multiple test cases. Process to the End of File.
Each test case contains 7 nonnegative integers as follows:
N
A0 AX AY
B0 BX BY
N is no more than 10 18, and all the other integers are no more than 2×10 9.
Output
For each test case, output AoD(N) modulo 1,000,000,007.
Sample Input
1
1 2 3
4 5 6
2
1 2 3
4 5 6
3
1 2 3
4 5 6
Sample Output
4
134
1902

这个题主要就是递推式不好推。。
我以为是3*3其实不是….
像这种递推可以找出多个未知量。。
我还是对递推这个概念了解的太浅了。。

#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
ll mo = 1e9 + 7;
struct p
{
    ll q[7][7];
};
p cheng(p q, p w)
{
    p fh;
    for (long long a = 0; a < 7; a++)
    {
        for (long long b = 0; b < 7; b++)
        {
            fh.q[a][b] = 0;
            for (long long c = 0; c < 7; c++)
            {
                fh.q[a][b] += (q.q[a][c] * w.q[c][b]) % (mo);
                fh.q[a][b] = (fh.q[a][b] + mo) % mo;
            }
        }
    }
    return fh;
}
p ksm(p ds, long long zs)
{
    p fs;
    for (long long a = 0; a < 7; a++)
    {
        for (long long b = 0; b < 7; b++)
        {
            if (a != b)fs.q[a][b] = 0;
            else fs.q[a][b] = 1;
        }
    }
    while (zs)
    {
        if (zs & 1)fs = cheng(fs, ds);
        ds = cheng(ds, ds);
        zs >>= 1;
    }
    return fs;
}
int main()
{
    long long n, a0, ax, ay, b0, bx, by;
    while (cin >> n >> a0 >> ax >> ay >> b0 >> bx >> by)
    {
        if (n == 0)
        {
            cout << 0 << endl;
            continue;
        }
        p ss =
        {
            {1,ax*bx%mo,ax*by%mo,bx*ay%mo,1,0,0,
            0,ax*bx%mo,ax*by%mo,bx*ay%mo,1,0,0,
            0,0,ax%mo,0,0,1,0,
            0,0,0,bx%mo,0,0,1,
            0,0,0,0,1,0,0,
            0,0,0,0,0,1,0,
            0,0,0,0,0,0,1}
        };
        ss = ksm(ss, n-1);
        ll e = a0*b0%mo*ss.q[0][0];
        e = (e + mo) % mo;
        e += a0*b0%mo*ss.q[0][1] % mo;
        e = (e + mo) % mo;
        e += ss.q[0][2] * a0%mo;
        e = (e + mo) % mo;
        e += ss.q[0][3] * b0%mo;
        e = (e + mo) % mo;
        e += ay*by%mo*ss.q[0][4];
        e = (e + mo) % mo;
        e += ay*ss.q[0][5];
        e = (e + mo) % mo;
        e += by*ss.q[0][6];
        e = (e + mo) % mo;
        cout << (e + mo) % mo << endl;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值