tribonacci
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的更多相关文章
- [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 + ...
- 【Leetcode_easy】1137. N-th Tribonacci Number
problem 1137. N-th Tribonacci Number solution: class Solution { public: int tribonacci(int n) { ) ; ...
- LeetCode.1137-第N个泰波那契数(N-th Tribonacci Number)
这是小川的第409次更新,第441篇原创 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第260题(顺位题号是1137).Tribonacci(泰波那契)序列Tn定义如下: 对于n&g ...
- 1137. N-th Tribonacci Number(Memory Usage: 13.9 MB, less than 100.00% of Python3)
其实思路很简单,套用一下普通斐波那契数列的非递归做法即可,不过这个成绩我一定要纪念一下,哈哈哈哈哈 代码在这儿: class Solution: def tribonacci(self, n: int ...
- 【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 ...
- 【LeetCode】1137. N-th Tribonacci Number 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetc ...
- 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 ...
- UVA12470—Tribonacci (类似斐波那契,简单题)
题目链接:https://vjudge.net/problem/UVA-12470 题目意思:我们都知道斐波那契数列F[i]=F[i-1]+F[i-2],现在我们要算这样的一个式子T[i]=T[i-1 ...
- Python简单试题
1,相乘次数 题目要求描述: 一个整数每一位上的数字相乘,判断是否为个位数,若是则程序结束 ,不是则继续相乘,要求返回相乘次数. 例:39 > 3*9=27 > 2*7=14 > 1 ...
随机推荐
- Cannot find module formidable
今天按照例子学习安装 formidable 即使我-g全局安装,也不行.. 于是搜到了这句话.. 解决了 我也遇到这个问题,困扰了我一天,现在找到解决办法了.我在看这篇入门教程:http://node ...
- Json 处理datetime
json怎么处理datetime类型 http://hi.baidu.com/culion/item/428df54bf36762aede2a9ff1
- keil c编译器错误与解决方法
1. Warning 280:’i’:unreferenced local variable 说明局部变量i 在函数中未作任何的存取操作解决方法消除函数中i 变量的宣告 2 Warning 206:’ ...
- 阿里云服务器重启后mysql不能启动的问题
环境:阿里云ECS服务器上,Ubuntu linux 12.04,64位版.MySQL 5.1. 首先查看/etc/rc.local,可以看到Ubuntu通过/etc/init.d/mysqld脚本启 ...
- BZOJ 1025 [SCOI2009]游戏
1025: [SCOI2009]游戏 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1533 Solved: 964[Submit][Status][ ...
- 【转】Android 带checkbox的listView 实现多选,全选,反选 -- 不错
原文网址:http://blog.csdn.net/onlyonecoder/article/details/8687811 Demo地址(0分资源):http://download.csdn.net ...
- DataGridView DataGridViewCheckBoxColumn编辑时实时触发事件
正常响应CellValueChanged()事件时,当改变checkbox状态时,只有当焦点离开该单元格时才能触发CellValueChanged()事件, 如果要改变checkbox值时实时触发Ce ...
- c宏的MAX函数
今天从香山上面回来累的跟傻逼一样,回来问了一下胡总的阿里面试的问题.然后其中有一个是宏写max函数.胡总说不好写,然后我就去洗澡了. 洗澡的时候感觉不对啊,回来写了一个: #define MAX(a, ...
- uploadify在struts2下的使用
1.首先准备uploadify上传插件包,拷贝到项目目录下 2.注意其中的特殊文件:uploadify-init.js文件,是包含了封装后的特殊函数: /** * uploadify上传插件相关JS ...
- Selenium 初见
Selenium名字的来源 在这里,我还想说一下关于Selenium名字的来源,很有意思的: >:Selenium的中文名为“硒”,是一种化学元素的名字,它对汞 (Mercury)有天然的解毒作 ...