Description
定义$F(x)$为$F(x−1)$与$F(x−2)$的连接(其中$F(0)="0"$,$F(1)="1"$)给出一个长度为$n$的$01$字符串$s$,询问$s$在$F(x)$
的所有子序列中出现了多少次。
$1≤n≤100$
$0≤x≤100$
Examples
Input
2 4
11
Output
14
Input
10 100
1010101010
Output
553403224

$f[i][l][r]$表示有多少$F[i]$的子序列里包含字符串[l,r]

有3种情况:

1.$l~r$都在$F[i-1]$中

2.$l~r$都在$F[i-2]$中

3.$l~k$在$F[i-1]$中,$k+1~r$都在$F[i-2]$中

对于第1种情况,如果$r=n$,那么$F[i-2]$就可以随便选

第二种情况也一样

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int Mod=1e9+;
int f[][][],len[],n,m;
char s[];
int qpow(int x,int y)
{
int res=;
while (y)
{
if (y&) res=1ll*res*x%Mod;
x=1ll*x*x%Mod;
y>>=;
}
return res;
}
int dfs(int x,int l,int r)
{int k;
if (f[x][l][r]!=-) return f[x][l][r];
if (x==||x==)
{
if (l==r&&s[l]==(char)(x+'')) return ;
return ;
}
int cnt=;
cnt+=1ll*dfs(x-,l,r)*((r==n)?qpow(,len[x-]):)%Mod;cnt%=Mod;
cnt+=1ll*dfs(x-,l,r)*((l==)?qpow(,len[x-]):)%Mod;cnt%=Mod;
for (k=l;k<r;k++)
{
cnt+=1ll*dfs(x-,l,k)*dfs(x-,k+,r)%Mod;
cnt%=Mod;
}
return f[x][l][r]=cnt;
}
int main()
{int i;
cin>>n>>m;
memset(f,-,sizeof(f));
len[]=;len[]=;
for (i=;i<=m;i++)
len[i]=(len[i-]+len[i-])%(Mod-);
cin>>s+;
printf("%d\n",dfs(m,,n));
}

codefroces 946F Fibonacci String Subsequences的更多相关文章

  1. [Codeforces 946F]Fibonacci String Subsequences

    Description 题库链接 定义 \(F(x)\) 为 \(F(x-1)\) 与 \(F(x-2)\) 的连接(其中 \(F(0) = "0",F(1) = "1& ...

  2. HDU 1708 简单dp问题 Fibonacci String

    Fibonacci String Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. HDOJ(HDU) 1708 Fibonacci String

    Problem Description After little Jim learned Fibonacci Number in the class , he was very interest in ...

  4. hdu 1708 Fibonacci String

    Fibonacci String Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...

  5. Fibonacci String(hdu 1708)

    Fibonacci String Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. DP 题集 1

    关于 DP 的一些题目 参考资料 [Tutorial] Non-trivial DP Tricks and Techniques DP Rain and Umbrellas Mr. Kitayuta, ...

  7. Educational Codeforces Round 39

    Educational Codeforces Round 39  D. Timetable 令\(dp[i][j]\)表示前\(i\)天逃课了\(j\)节课的情况下,在学校的最少时间 转移就是枚举第\ ...

  8. 杭电1708Fibonacci String

    Fibonacci String Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. Typescript学习笔记

    什么是 TypeScript TypeScript 是 JavaScript 的类型的超集,它可以编译成纯 JavaScript. 安装 TypeScript 命令行工具安装: npm install ...

随机推荐

  1. 巨人大哥谈Java中的Synchronized关键字用法

    巨人大哥谈Java中的Synchronized关键字用法 认识synchronized 对于写多线程程序的人来说,经常碰到的就是并发问题,对于容易出现并发问题的地方价格synchronized基本上就 ...

  2. 听翁恺老师mooc笔记(14)--格式化的输入与输出

    关于C语言如何做文件和底层操作: 文件操作,从根本上说,和C语言无关.这部分的内容,是教你如何使用C语言的标准库所提供的一系列函数来操作文件,最基本的最原始的文件操作.你需要理解,我们在这部分所学习的 ...

  3. Struts2之Struts2的下载与安装

    Struts2的下载 登陆struts的官网 下载Full Distribution这个选项的struts2的包. 这是Struts2的完整版,里面包括Struts2的实例应用,空实例应用,核心库,源 ...

  4. bzoj千题计划252:bzoj1095: [ZJOI2007]Hide 捉迷藏

    http://www.lydsy.com/JudgeOnline/problem.php?id=1095 点分树+堆 请去看 http://www.cnblogs.com/TheRoadToTheGo ...

  5. HTML5 canvas绘制雪花飘落

    Canvas是HTML5新增的组件,它就像一块幕布,可以用JavaScript在上面绘制各种图表.动画等. 没有Canvas的年代,绘图只能借助Flash插件实现,页面不得不用JavaScript和F ...

  6. nyoj VF

    VF 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Vasya is the beginning mathematician. He decided to make ...

  7. :after/:before使用技巧

    伪类:after/:before基本使用 div:before{ content:'';//必须要写,没写则伪元素无效 display:; position:''; ... } //在一个div子元素 ...

  8. php的开发的apache的配置及伪静态的应用

    1.Apache之所以能够解析php代码是游览器首先发送数据到模版页面,然后模版页提交数据到php页面,然后php代码经过Apache解析过后生成结果的,所以是 在Apache的配置文件中是可以看到开 ...

  9. github提交代码到服务器的方法

    第一种情况,没有冲突:1.git add .//进入到center的项目下将本地文件打包的意思2.git pull origin dev//将服务器的代码下载到本地如果是最新的会提示Already u ...

  10. Service Worker和HTTP缓存

    很多人,包括我自己,初看Service Worker多一个Cache Storage的时候,就感觉跟HTTP长缓存没什么区别. 例如大家讲的最多的Service Worker能让网页离线使用,但熟悉H ...