Everybody knows Fibonacci numbers, now we are talking about the Tribonacci numbers: 
T[0] = T[1] = T[2] = 1; 
T[n] = T[n - 1] + T[n - 2] + T[n - 3] (n >= 3)

Given a and b, you are asked to calculate the sum from the ath Fibonacci number to the bth Fibonacci number, mod 1,000,000,007, that is (T[a] + T[a + 1] + ... + T[b]) % 1,000,000,007.

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

;
;

__int64 N;

void multipy( __int64 a[MAX_N][MAX_N], __int64 b[MAX_N][MAX_N], __int64 c[MAX_N][MAX_N] ){
    ; i <= ; i++ ){
        ; j <= ; j++ ){
            c[i][j] = ;
            ; k <= ; k++ ){
                c[i][j] = ( c[i][j] + a[i][k] * b[k][j] % MOD ) % MOD;
            }
        }
    }
}

void get_matrix_pow( __int64 a[MAX_N][MAX_N], __int64 n ){
    __int64 ans[MAX_N][MAX_N] = {};
    __int64 temp[MAX_N][MAX_N];
    ; i <= ; i++ )   ans[i][i] = ;

    while( n ){
         ==  ){
            multipy( ans, a, temp );
            memcpy( ans, temp, sizeof( __int64 ) * MAX_N * MAX_N );
        }
        multipy( a, a, temp );
        memcpy( a, temp, sizeof( __int64 ) * MAX_N * MAX_N );
        n /= ;
    }
    memcpy( a, ans, sizeof( __int64 ) * MAX_N * MAX_N );
}

__int64 solve( __int64 n ){
    __int64 a[MAX_N][MAX_N] = {};
     ){
        ;
    }
     ){
        ;
    } ){
        ;
    }
    a[][] = ;a[][] = ;a[][] = ;a[][] = ;
    a[][] = ;a[][] = ;a[][] = ;a[][] = ;
    a[][] = ;a[][] = ;a[][] = ;a[][] = ;
    a[][] = ;a[][] = ;a[][] = ;a[][] = ;
    get_matrix_pow( a, n -  );
    __int64 ans = ;
    __int64 b[MAX_N];
    b[] = b[] = b[] = ;
    b[] = ;
    ; i <= ; i++ ){
        ans = ( ans + a[][i] * b[i] % MOD ) % MOD;
    }
    return ans;
}

int main(){
    __int64 A, B;
    while( scanf( "%I64d%I64d", &A, &B ) != EOF ){
        printf(  ) + MOD ) % MOD );
    }
    ;
}

tribonacci的更多相关文章

  1. [LeetCode] 1137. N-th Tribonacci Number

    Description e Tribonacci sequence Tn is defined as follows: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + ...

  2. 【Leetcode_easy】1137. N-th Tribonacci Number

    problem 1137. N-th Tribonacci Number solution: class Solution { public: int tribonacci(int n) { ) ; ...

  3. LeetCode.1137-第N个泰波那契数(N-th Tribonacci Number)

    这是小川的第409次更新,第441篇原创 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第260题(顺位题号是1137).Tribonacci(泰波那契)序列Tn定义如下: 对于n&g ...

  4. 1137. N-th Tribonacci Number(Memory Usage: 13.9 MB, less than 100.00% of Python3)

    其实思路很简单,套用一下普通斐波那契数列的非递归做法即可,不过这个成绩我一定要纪念一下,哈哈哈哈哈 代码在这儿: class Solution: def tribonacci(self, n: int ...

  5. 【leetcode】1137. N-th Tribonacci Number

    题目如下: The Tribonacci sequence Tn is defined as follows: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 ...

  6. 【LeetCode】1137. N-th Tribonacci Number 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetc ...

  7. Tribonacci UVA - 12470 (简单的斐波拉契数列)(矩阵快速幂)

    题意:a1=0;a2=1;a3=2; a(n)=a(n-1)+a(n-2)+a(n-3);  求a(n) 思路:矩阵快速幂 #include<cstdio> #include<cst ...

  8. UVA12470—Tribonacci (类似斐波那契,简单题)

    题目链接:https://vjudge.net/problem/UVA-12470 题目意思:我们都知道斐波那契数列F[i]=F[i-1]+F[i-2],现在我们要算这样的一个式子T[i]=T[i-1 ...

  9. Python简单试题

    1,相乘次数 题目要求描述: 一个整数每一位上的数字相乘,判断是否为个位数,若是则程序结束 ,不是则继续相乘,要求返回相乘次数. 例:39 > 3*9=27 > 2*7=14 > 1 ...

随机推荐

  1. poj 1113Wall

    http://poj.org/problem?id=1113 #include<cstdio> #include<cstring> #include<cstdlib> ...

  2. BestCoder Round #49

    呵呵哒,1001的dfs返回值写错,wa了两发就没分了,1002显然是PAM可是我没学过啊!!!压位暴力可不可以...看看范围貌似不行,弃疗...1003根本不会做,1004想了想lcc发现不可做,那 ...

  3. COJ 0342 逆序对(一)

    传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=312 试题描述: 给你一个大小为N的int数组A.请你统计有多少数对(Ai, ...

  4. SPFA 最短路径打印方法

    #include <iostream> #include <cstdlib> #include <cstdio> #include <algorithm> ...

  5. 【转】Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果--不错

    原文网址:http://blog.csdn.net/xiaanming/article/details/10163203 转载请注明出处:http://blog.csdn.net/xiaanming/ ...

  6. 实Schur分解

        前面已经说过LU,Cholesky和QR分解,这次介绍的是实Schur分解.对这个分解的定义是任意一个矩阵A,可有如下形式的分解:               U*A*U' = B;其中B是拟 ...

  7. Repo安装遇到问题

    问题一: “The program 'repo' is currently not installed. You can install it by typing: sudo apt-get inst ...

  8. NDN与TCP/IP

    搬运自http://blog.csdn.net/programmer_at/article/details/49203241  当前TCP/IP协议存在哪些问题?如何改进? 当时没有回答好,然后提到了 ...

  9. angularjs改变路由时控制器每次都执行两次

    原因如下: 代码里面也初始化了控制器 模板配置了一个控制器

  10. Java做acm所需要的基础知识之排序问题

    Java做acm所需要的基础知识. 以前做acm的题都是用C/C++来写代码的,在学习完Java之后突然感觉Java中的方法比C/C++丰富很多,所以就整理一下平时做题需要用到的Java基础知识. 1 ...