hihocoder#1239 : Fibonacci(递推DP)
来源:互联网 发布:温莎公爵间谍 知乎 编辑:程序博客网 时间:2024/05/22 11:37
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
- 样例输入
62 1 1 2 2 3
- 样例输出
7
描述
Given a sequence {an}, how many non-empty sub-sequence of it is a prefix of fibonacci sequence.
A sub-sequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
The fibonacci sequence is defined as below:
F1 = 1, F2 = 1
Fn = Fn-1 + Fn-2, n>=3
输入
One line with an integer n.
Second line with n integers, indicating the sequence {an}.
For 30% of the data, n<=10.
For 60% of the data, n<=1000.
For 100% of the data, n<=1000000, 0<=ai<=100000.
输出
One line with an integer, indicating the answer modulo 1,000,000,007.
样例提示
The 7 sub-sequences are:
{a2}
{a3}
{a2, a3}
{a2, a3, a4}
{a2, a3, a5}
{a2, a3, a4, a6}
{a2, a3, a5, a6}
#include<bits/stdc++.h>using namespace std;const int MAX=1e6+10;const int MOD=1e9+7;int A[MAX],v[MAX]; //v[i]表示Fibonacci数i的下标int f[30],n,d[MAX][30];int main(){ scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&A[i]); f[1]=f[2]=1; for(int i=3;f[i-2]+f[i-1]<=1e5;i++) { f[i]=f[i-1]+f[i-2]; v[f[i]]=i; } memset(d,0,sizeof d); for(int i=1;i<=n;i++) { for(int j=1;j<30;j++)d[i][j]=d[i-1][j]; if(A[i]==1) { d[i][1]=(d[i][1]+1)%MOD; d[i][2]=(d[i][2]+d[i-1][1])%MOD; } else d[i][v[A[i]]]=(d[i][v[A[i]]]+d[i-1][v[A[i]]-1])%MOD; } int ans=0; for(int i=1;i<30;i++)ans=(ans+d[n][i])%MOD; cout<<ans<<endl; return 0;}
阅读全文
1 0
- hihocoder#1239 : Fibonacci(递推DP)
- hihocoder#1096 : Divided Product(递推DP)
- hihoCoder 1239 Fibonacci
- hihoCoder 1239 Fibonacci
- hihocoder 1259 推公式+数位dp(非dfs写法)
- codeforces 126D Fibonacci Sums 递推 DP
- hdu 1708 Fibonacci String (递推)
- python fibonacci 递推
- 递推dp(uva10404)
- 递推(dp)-HDU5366
- [HDU1588]Gauss Fibonacci(递推+矩阵快速幂)
- 【hihocoder #1506 : 投掷硬币】递推
- hdu1588---Gauss Fibonacci(矩阵,线性递推)
- 【POJ】3070 Fibonacci 递推+矩阵优化
- POJ 2229 Sumsets(dp 递推)
- uva1638(递推关系,dp)
- B. Working out (递推dp )
- POJ2385 Apple Catching(DP/递推)
- 苹果收购的这家法国计算机视觉公司,可通过AI来确定性别、年龄、情感
- 20年后的iphoneXXXX手机长这样
- SpaceX发布震撼宣传片:坐火箭出行 纽约到上海仅需半小时
- PAT 甲级 1056. Mice and Rice (25)
- hadoop源码
- hihocoder#1239 : Fibonacci(递推DP)
- 解析php中die(),exit(),return的区别
- 51nod 1043 幸运号码
- Parallel复制虚拟机之网卡配置
- 查看MySQL版本号的四种方式
- 个人网站上线的经历
- LeetCode#654 Maximum Binary Tree题解(C++版)
- 常用数据结构——栈及其应用
- 期望DP入门 HDU