HDU 6880 Permutation Counting dp
2024-08-31 14:46:19
题意:
给你一个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;
}
最新文章
- 深入浅出Redis-redis哨兵集群
- HDU5769 Substring(后缀数组)
- VB调用sendinput API
- jQuery停止动画——stop()方法的使用
- Windows Phone 8下 友盟社会化组件SDK的使用。
- 把ZenCart在线商店搭建到本地
- T-SQL查询进阶--深入浅出视图
- Spring AOP简介
- 《C++ Primer 4th》读书笔记 第7章-函数
- angularjs应用骨架(3)
- 交叉编译环境以及开发板上-/bin/sh: ./hello: not found(使用arm-linux-gcc -static -o 来进行静态编译)
- Qt之窗口动画(下坠、抖动、透明度)(还有好多相关帖子)
- MySQL 常用基础命令
- 用Mockito测试SpringMVC+Hibernate
- 7.java的请求转发和请求重定向
- 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
- 六星经典CSAPP-笔记(12)并发编程(上)
- Docker(二)搭建和使用Docker
- PY3 多组输入
- Windows和pthread中提供的自旋锁