Description

Link.

\[\sum\prod_{i=1}^{m}F_{a_{i}},(m>0,a_{1},\cdots a_{m}>0,\sum a_{i}=n)
\]

Solution

这是一篇不用 \(\mathbf{OGF}\) 的题解。

设 \(f_{i}\) 为 \(i\) 的 \(\operatorname{lqp}\) 拆分值。

然后有显然的过不了递推式:

\[f_{n}=\begin{cases}
1,n=0 \\
\displaystyle
\sum_{i=0}^{n-1}F_{n-i}\times f_{i},n\neq0
\end{cases}
\]

然后传统艺能错位相减操作一下:

\[\begin{aligned}
f_{n}&=\sum_{i=0}^{n-1}F_{n-i}\times f_{i} \\
f_{n-1}&=\sum_{i=0}^{n-2}F_{n-i-1}\times f_{i} \\
f_{n-2}&=\sum_{i=0}^{n-3}F_{n-i-2}\times f_{i}
\end{aligned}
\Longrightarrow
\begin{aligned}
f_{n}-f_{n-1}-f_{n-2}&=\sum_{i=0}^{n-1}F_{n-i}\times f_{i}-\sum_{i=0}^{n-2}F_{n-i-1}\times f_{i}-\sum_{i=0}^{n-3}F_{n-i-2}\times f_{i} \\
f_{n}-f_{n-1}-f_{n-2}&=(F_{2}-F_{1})\times f_{n-2}+F_{1}\times f_{n-1}
\end{aligned}
\\
\downarrow \\
f_{n}=2f_{n-1}+f_{n-2}
\]

递推公式有了,然后矩阵快速幂:

\[\begin{bmatrix}
f_{n} \\
f_{n-1}
\end{bmatrix}
=\begin{bmatrix}
2f_{n-1}+f_{n-2} \\
f_{n-1}
\end{bmatrix}
=\begin{bmatrix}
f_{n-1} \\
f_{n-2}
\end{bmatrix}
\times\begin{bmatrix}
2 & 1 \\
1 & 0
\end{bmatrix}
\]

这样就可以做了(吗?):

(code?)

#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#define mod ( 1000000007 ) using namespace std;
typedef long long LL; template<typename _T, typename _P>
_T qkpow( _T bas, _T one, _P fur ){
_T res = one;
while( fur != 0 ){
if( fur % 2 == ( _P )1 ) res = bas * res;
bas = bas * bas;
fur /= 2;
}
return res;
} template<typename _T>
_T add( _T x, _T y ){ if( y >= mod ) y %= mod; x += y; if( x >= mod ) x -= mod; return x; } struct bigInt : vector<int>{
bigInt &check( ){
while( ! empty( ) && ! back( ) ) pop_back( );
if( empty( ) ) return *this;
for( unsigned i = 1; i < size( ); ++ i ){ ( *this )[i] += ( *this )[i - 1] / 10; ( *this )[i - 1] %= 10; }
while( back( ) >= 10 ){ push_back( back( ) / 10 ); ( *this )[size( ) - 2] %= 10; }
return *this;
}
bigInt( int tpN = 0 ){ push_back( tpN ); check( ); }
};
istream &operator >> ( istream &is, bigInt &tpN ){
string s;
is >> s; tpN.clear( );
for( int i = s.size( ) - 1; i >= 0; --i ) tpN.push_back( s[i] - '0' );
return is;
}
ostream &operator << ( ostream &os, const bigInt &tpN ){
if( tpN.empty( ) ) os << 0;
for( int i = tpN.size( ) - 1; i >= 0; --i ) os << tpN[i];
return os;
}
bool operator != ( const bigInt &one, const bigInt &another ){
if( one.size( ) != another.size( ) ) return 1;
for( int i = one.size( ) - 1; i >= 0; --i ){
if( one[i] != another[i] ) return 1;
}
return 0;
}
bool operator == ( const bigInt &one, const bigInt &another ){
return ! ( one != another );
}
bool operator < ( const bigInt &one, const bigInt &another ){
if( one.size( ) != another.size( ) ) return one.size( ) < another.size( );
for( int i = one.size( ) - 1; i >= 0; --i ){
if( one[i] != another[i] ) return one[i] < another[i];
}
return 0;
}
bool operator > ( const bigInt &one, const bigInt &another ){ return another < one; }
bool operator <= ( const bigInt &one, const bigInt &another ){ return ! (one > another ); }
bool operator >= ( const bigInt &one, const bigInt &another ){ return ! (one < another ); }
bigInt &operator += ( bigInt &one, const bigInt &another ){
if( one.size( ) < another.size( ) ) one.resize(another.size( ) );
for( unsigned i = 0; i != another.size( ); ++ i ) one[i] += another[i];
return one.check( );
}
bigInt operator + ( bigInt one, const bigInt &another ){ return one += another; }
bigInt &operator -= ( bigInt &one, bigInt another ){
if( one < another ) swap( one, another );
for( unsigned i = 0; i != another.size( ); one[i] -= another[i], ++ i ){
if( one[i] < another[i] ){
unsigned j = i + 1;
while( ! one[j] ) ++ j;
while( j > i ){ -- one[j]; one[--j] += 10; }
}
}
return one.check( );
}
bigInt operator - ( bigInt one, const bigInt &another ){ return one -= another; }
bigInt operator * ( const bigInt &one, const bigInt &another ){
bigInt tpN;
tpN.assign( one.size( ) + another.size( ) - 1, 0 );
for( unsigned i = 0; i != one.size( ); ++ i ){
for( unsigned j = 0; j != another.size( ); ++ j ) tpN[i + j] += one[i] * another[j];
}
return tpN.check( );
}
bigInt &operator *= ( bigInt &one, const bigInt &another ){ return one = one * another; }
bigInt divMod( bigInt &one, const bigInt &another ){
bigInt ans;
for( int t = one.size( ) - another.size( ); one >= another; -- t ){
bigInt tpS;
tpS.assign( t + 1, 0 );
tpS.back( ) = 1;
bigInt tpM = another * tpS;
while( one >= tpM ){ one -= tpM; ans += tpS; }
}
return ans;
}
bigInt operator / ( bigInt one, const bigInt &another ){ return divMod(one, another ); }
bigInt &operator /= ( bigInt &one, const bigInt &another ){ return one = one / another; }
bigInt &operator %= ( bigInt &one, const bigInt &another ){ divMod( one, another ); return one; }
bigInt operator % ( bigInt one, const bigInt &another ){ return one %= another; } struct matrixS{
int mat[2][2];
matrixS( int x = 0 ){ memset( mat, x, sizeof( mat ) ); }
matrixS operator * ( const matrixS &another ) const{
matrixS res;
for( int i = 0; i < 2; ++ i ){
for( int j = 0; j < 2; ++ j ){
for( int k = 0; k < 2; ++ k ) res.mat[i][j] = add( ( LL )res.mat[i][j], ( LL )mat[i][k] * another.mat[k][j] );
}
}
return res;
}
} unit, erng; bigInt N; void progressBaseInformation( ){
int unitS[2][2] = { { 1, 0 }, { 0, 1 } };
memcpy( unit.mat, unitS, sizeof( unitS ) );
int erngS[2][2] = { { 2, 1 }, { 1, 0 } };
memcpy( erng.mat, erngS, sizeof( erngS ) );
} signed main( ){
ios::sync_with_stdio( 0 ); cin.tie( 0 ); cout.tie( 0 );
progressBaseInformation( );
cin >> N; cout << qkpow( erng, unit, N ).mat[1][0] << '\n';
return 0;
}

不,凉心出题人友好地卡了高精的常数,于是你打开题解,发现 \(f_{n}=f_{n\bmod (10^{9}+6)}\),于是你又行了。

\(\mathcal{Code}\)

#include <cstdio>
#include <cstring>
#include <queue>
#define mod ( 1000000007 ) using namespace std;
typedef long long LL; template<typename _T>
void read( _T &x ){
x = 0; char c = getchar( ); _T f = 1;
while( c < '0' || c > '9' ){ if( c == '-' ) f = -1; c = getchar( ); }
while( c >= '0' && c <= '9' ){ x = ( ( x << 3 ) + ( x << 1 ) + ( c & 15 ) ) % ( mod - 1 ); c = getchar( ); }
x *= f;
} template<typename _T>
void write( _T x ){
if( x < 0 ){ putchar( '-' ); x = -x; }
if( x > 9 ) write( x / 10 );
putchar( x % 10 + '0' );
} template<typename _T, typename _P>
_T qkpow( _T bas, _T one, _P fur ){
_T res = one;
while( fur != 0 ){
if( fur % 2 == ( _P )1 ) res = bas * res;
bas = bas * bas;
fur /= 2;
}
return res;
} template<typename _T>
_T add( _T x, _T y ){ if( y >= mod ) y %= mod; x += y; if( x >= mod ) x -= mod; return x; } struct matrixS{
int mat[2][2];
matrixS( int x = 0 ){ memset( mat, x, sizeof( mat ) ); }
matrixS operator * ( const matrixS &another ) const{
matrixS res;
for( int i = 0; i < 2; ++ i ){
for( int j = 0; j < 2; ++ j ){
for( int k = 0; k < 2; ++ k ) res.mat[i][j] = add( ( LL )res.mat[i][j], ( LL )mat[i][k] * another.mat[k][j] );
}
}
return res;
}
} unit, erng; LL N; void progressBaseInformation( ){
int unitS[2][2] = { { 1, 0 }, { 0, 1 } };
memcpy( unit.mat, unitS, sizeof( unitS ) );
int erngS[2][2] = { { 2, 1 }, { 1, 0 } };
memcpy( erng.mat, erngS, sizeof( erngS ) );
} signed main( ){
progressBaseInformation( );
read( N ); write( qkpow( erng, unit, N ).mat[1][0] ), putchar( '\n' );
return 0;
}

Solution -「洛谷 P4451」「国家集训队」整数的 lqp 拆分的更多相关文章

  1. 【洛谷】1852:[国家集训队]跳跳棋【LCA】【倍增?】

    P1852 [国家集训队]跳跳棋 题目背景 原<奇怪的字符串>请前往 P2543 题目描述 跳跳棋是在一条数轴上进行的.棋子只能摆在整点上.每个点不能摆超过一个棋子. 我们用跳跳棋来做一个 ...

  2. 【洛谷】1494:[国家集训队]小Z的袜子【莫队】

    P1494 [国家集训队]小Z的袜子 题目描述 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命…… ...

  3. Solution -「国家集训队」「洛谷 P4451」整数的 lqp 拆分

    \(\mathcal{Description}\)   Link.   求 \[\sum_{m>0\\a_{1..m}>0\\a_1+\cdots+a_m=n}\prod_{i=1}^mf ...

  4. 洛谷P1903 数颜色 [国家集训队] 莫队

    正解:带修莫队 解题报告: 可以理解为引入时间参数,然后就是有了仨参数,关于这个修改同样的是,如果时间是相同的,不用搞,如果时间不相同做一下时光倒流/时光推移就成嘛 但是肯定既然这样的话,按照原来的s ...

  5. 题解 洛谷P1903/BZOJ2120【[国家集训队]数颜色 / 维护队列】

    对于不会树套树.主席树的本蒟蒻,还是老老实实的用莫队做吧.... 其实这题跟普通莫队差不了多远,无非就是有了一个时间,当我们按正常流程排完序后,按照基本的莫队来,做莫队时每次循环对于这一次操作,我们在 ...

  6. 题解 洛谷P1501/BZOJ2631【[国家集训队]Tree II】

    Link-Cut-Tree 的懒标记下传正确食用方法. 我们来逐步分析每一个操作. 1:+ u v c:将u到v的路径上的点的权值都加上自然数c; 解决方法: 很显然,我们可以 split(u,v) ...

  7. 洛谷 P1505 BZOJ 2157 [国家集训队]旅游

    bzoj题面 Time limit 10000 ms Memory limit 265216 kB OS Linux 吐槽 又浪费一个下午--区间乘-1之后,最大值和最小值更新有坑.新的最大值是原来最 ...

  8. 「区间DP」「洛谷P1043」数字游戏

    「洛谷P1043」数字游戏 日后再写 代码 /*#!/bin/sh dir=$GEDIT_CURRENT_DOCUMENT_DIR name=$GEDIT_CURRENT_DOCUMENT_NAME ...

  9. 「 洛谷 」P2768 珍珠项链

    珍珠项链 题目限制 内存限制:125.00MB 时间限制:1.00s 标准输入输出 题目知识点 动态规划 \(dp\) 矩阵 矩阵乘法 矩阵加速 矩阵快速幂 题目来源 「 洛谷 」P2768 珍珠项链 ...

  10. 「 洛谷 」P4539 [SCOI2006]zh_tree

    小兔的话 推荐 小兔的CSDN [SCOI2006]zh_tree 题目限制 内存限制:250.00MB 时间限制:1.00s 标准输入输出 题目知识点 思维 动态规划 \(dp\) 区间\(dp\) ...

随机推荐

  1. STL-queue(ACM)

    重构函数(默认) queue<int> q; 基本操作 q.front(); // 队列最前面的元素q.back(); // 队列最后面的元素q.size(); // 返回队列长度q.em ...

  2. 插件化工程R文件瘦身技术方案 | 京东云技术团队

    随着业务的发展及版本迭代,客户端工程中不断增加新的业务逻辑.引入新的资源,随之而来的问题就是安装包体积变大,前期各个业务模块通过无用资源删减.大图压缩或转上云.AB实验业务逻辑下线或其他手段在降低包体 ...

  3. C++面试八股文:什么是RAII?

    某日二师兄参加XXX科技公司的C++工程师开发岗位第13面: 面试官:什么是RAII? 二师兄:RAII是Resource Acquisition Is Initialization的缩写.翻译成中文 ...

  4. [ARM汇编]计算机原理与数制基础—1.1.3 二进制补码

    在计算机中,为了表示有符号整数(即正数和负数),通常采用二进制补码表示法.二进制补码不仅可以表示负数,还能简化计算机的加法和减法运算.接下来,我们将介绍二进制补码的概念及其计算方法. 原码.反码和补码 ...

  5. 【论文阅读】Pyramid Scene Parsing Network

    解决的问题:(FCN) Mismatched Relationship: 匹配关系错误,如将在水中的船识别为车. Confusion Categories: 模糊的分类,如 hill 和 mounta ...

  6. PHP处理模板 cookie优先 检测用户登录

    <?php// +----------------------------------------------------------------------// | easy pay [ pa ...

  7. Lifecycle解决了什么问题,以及它的基本用法

    1.为何要引入Lifecycle? 我首先来举个大家都比较常见的例子:我们在android开发的时候,经常需要在页面的onCreate()方法中对组件进行初始化,在onPause()方法中停止组件,而 ...

  8. gin 接口开发 - 用户输入自动 TrimSpace

    最近在思考一个问题,针对用户的输入,能不能快速校验? 比方说下面的 struct,大家用过 gin 的就知道,支持指定某个字段为 required,用户如果不输入,就检验不通过. type Login ...

  9. PHP递归和循环的速度测试

    本文于 2017-12-05 重新整理. 写了一个可以对 $_GET, $_POST 等输入进行过滤的函数,递归实现如下: function array_map_recursive($filters, ...

  10. 信创啊,信创。Solon 的 war 包,现在同时支持 jakarta.servlet(及 javax.servlet)容器了!

    Solon 是个神奇的项目,不是基于 Servlet 的.但是又很支持 Servlet,尤其是 war 包.打起来还挺方便的. 如果你是做信创的(听说,很多信创项目是用 war 部署到 tomcat ...