题意:

给你一个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;
}

HDU 6880 Permutation Counting dp的更多相关文章

  1. hdu 3664 Permutation Counting(水DP)

    Permutation Counting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  2. HDU - 3664 Permutation Counting 排列规律dp

    Permutation Counting Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-value as the ...

  3. HDU 3664 Permutation Counting (DP)

    题意:给一个 n,求在 n 的所有排列中,恰好有 k 个数a[i] > i 的个数. 析:很明显是DP,搞了好久才搞出来,觉得自己DP,实在是太low了,思路是这样的. dp[i][j]表示 i ...

  4. HDU - 3664 Permutation Counting

    Discription Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-value as the amount of ...

  5. hdu3664 Permutation Counting(dp)

    hdu3664 Permutation Counting 题目传送门 题意: 在一个序列中,如果有k个数满足a[i]>i:那么这个序列的E值为k,问你 在n的全排列中,有多少个排列是恰好是E值为 ...

  6. HDU3664 Permutation Counting

    Permutation Counting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. HDU 1011 树形背包(DP) Starship Troopers

    题目链接:  HDU 1011 树形背包(DP) Starship Troopers 题意:  地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...

  8. hdu 2296 aC自动机+dp(得到价值最大的字符串)

    Ring Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. HDU 4778 状压DP

    一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...

随机推荐

  1. docker 容器和镜像的常用命令

    镜像 docker rmi 镜像id -f # 删除指定镜像 docker rmi 镜像id 镜像id -f # 删除多个镜像 docker rmi -f $(docker images -aq) # ...

  2. 【RAC】安装cluster软件 在节点2执行root.sh脚本

    安装cluster软件  在节点2执行root.sh脚本 报错如下: Running vipca(silent) for configuring nodeapps /db/oracle/product ...

  3. kubectl命令管理

    kubectl命令管理 查看更多帮助命令 [root@k8s-master ~]# kubectl --help 创建一个命名空间 [root@k8s-master ~]# kubectl creat ...

  4. powershell中的cmdlet命令

    Add-Computer 向域或工作组中添加计算机. Add-Content 向指定的项中添加内容,如向文件中添加字词. Add-History 向会话历史记录追加条目. Add-Member 向 W ...

  5. SAP中的F4帮助

    今天在调试标准程序的时候,意外的发现了一个F4帮助的函数,感觉还是挺好用的. F4IF_FIELD_VALUE_REQUEST从函数名就可以看出是给字段添加F4帮助的. F4 help for fie ...

  6. 深入研究.NET 5的开放式遥测

    OpenTelemetry 介绍 OpenTelemetry是一种开放的源代码规范,工具和SDK,用于检测,生成,收集和导出遥测数据(指标,日志和跟踪),开放遥测技术得到了Cloud Native C ...

  7. 浅析鸿蒙中的 Gn 与 Ninja(一)

    目录: Ninja简介 make 的 3 个特性 举例说明Ninja 的用法 如何向构建工具 Ninja 描述构建图 后记 鸿蒙系统的编译构建是基于 Gn 和 Ninja 完成的,那么 Gn 和 Ni ...

  8. VMware 虚拟机逃逸漏洞

    所谓虚拟机逃逸(Escape Exploit),指的是突破虚拟机的限制,实现与宿主机操作系统交互的一个过程,攻击者可以通过虚拟机逃逸感染宿主机或者在宿主机上运行恶意软件. 针对 VMware 的虚拟机 ...

  9. 20200927gryz校赛心得

    今天gyh学长给我们办了一场校内模拟赛,特地跑来记录一下心得 昨天晚上问了一下lkp学长,听说题目不卡常,不毒瘤,因此我在考试前20分钟仍在若无其事的练习着刚学的强连通分量,丝毫不慌 结果虽然rank ...

  10. List对象集合根据组合属性进行差集运算

    背景   当List是一个基本数据类型的集合的时候,进行集合运算还比较方便,但是有这么一些业务场景,比如某个用户权限变化的列表,或者取数据的变化结果,当时有时候用笨方法多循环两次也是可以的,只不过代码 ...