题意:

给你一个n和一个长度为n-1的由0/1构成的b序列

你需要从[1,n]中构造出来一个满足b序列的序列

我们设使用[1,n]构成的序列为a,那么如果ai>ai+1,那么bi=1,否则bi=0

问你你可以构造出来多少满足b序列的序列a

代码:

看官方题解

代码:

#include<stack>
#include<queue>
#include<map>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn=2000+10;
const int mod=1e9+7;
const double eps=1e-8;
const int INF = 0x3f3f3f3f;
int a[5010],dp[5010][5010];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=1; i<=n-1; i++)
{
cin>>a[i];
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
dp[i][j]=0;
}
}
if(a[1]==1)
{
dp[2][1]=1;
dp[2][2]=0;
}
else
{
dp[2][2]=1;
dp[2][1]=0;
}
for(int i=2; i<=n-1; i++)
{
if(a[i]==1)
{
for(int j=i; j>=1; j--)
{
dp[i+1][j]=(dp[i+1][j+1]+dp[i][j])%mod;
}
}
else
{
dp[i+1][1]=0;
for(int j=2; j<=i+1; j++)
{
dp[i+1][j]=(dp[i][j-1]+dp[i+1][j-1])%mod;
}
}
}
int res=0;
for(int i=1; i<=n; i++) res=(res+dp[n][i])%mod;
cout<<res<<endl;
}
return 0;
}

最新文章

  1. 深入浅出Redis-redis哨兵集群
  2. HDU5769 Substring(后缀数组)
  3. VB调用sendinput API
  4. jQuery停止动画——stop()方法的使用
  5. Windows Phone 8下 友盟社会化组件SDK的使用。
  6. 把ZenCart在线商店搭建到本地
  7. T-SQL查询进阶--深入浅出视图
  8. Spring AOP简介
  9. 《C++ Primer 4th》读书笔记 第7章-函数
  10. angularjs应用骨架(3)
  11. 交叉编译环境以及开发板上-/bin/sh: ./hello: not found(使用arm-linux-gcc -static -o 来进行静态编译)
  12. Qt之窗口动画(下坠、抖动、透明度)(还有好多相关帖子)
  13. MySQL 常用基础命令
  14. 用Mockito测试SpringMVC+Hibernate
  15. 7.java的请求转发和请求重定向
  16. Caused by: java.sql.SQLException: Couldn&#39;t perform the operation getAutoCommit: You can&#39;t perform any operations on this connection. It has been automatically closed by Proxool for some reason (see lo
  17. 六星经典CSAPP-笔记(12)并发编程(上)
  18. Docker(二)搭建和使用Docker
  19. PY3 多组输入
  20. Windows和pthread中提供的自旋锁

热门文章

  1. 【Java基础】基本语法-变量与运算符
  2. 【Redis3.0.x】发布订阅
  3. win7安装oracle11g和oracle client和pl/sql
  4. 【Oracle LISTNER】oracle Listener 宕机解决办法
  5. Netty学习:ChannelHandler执行顺序详解,附源码分析
  6. oracle dataguard搭建
  7. 把vscode打造成技术写作神器
  8. C# 关机/重启/注销计算机
  9. mysql 设置外键约束时如何删除数据
  10. uni-app开发经验分享二十一: 图片滑动解锁插件制作解析