牛客第一场 E-ABAB

题目

题意:一个长度为2(n+m)的串 有(n+m)个A 和B     问有多少个这种串能使得其拆分为 n个AB  和m个BA

 

首先 前n个A肯定是AB的A   前m个B肯定是BA的B (或者说可以将其视作)  (假设将前n个A 的某一个看作是BA的A  那么在序列的后端同样可以找出一个A 作为该BA的A   所以可以将其视为AB的A)

dp[i][j] 表示放置i个A  和j个B

 

#include<bits/stdc++.h>
using namespace std;
//input by bxd
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i>=(b);--i)
#define RI(n) scanf("%d",&(n))
#define RII(n,m) scanf("%d%d",&n,&m)
#define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define RS(s) scanf("%s",s)
#define ll long long
#define see(x) (cerr<<(#x)<<'='<<(x)<<endl)
#define pb push_back
#define inf 0x3f3f3f3f
#define CLR(A,v)  memset(A,v,sizeof A)
typedef pair<int,int>pii;
//
const int N=2108;
const int mod=1e9+7;
int n,m;
ll dp[N][N];

ll sol()
{
    rep(i,0,n+m)rep(j,0,n+m)dp[i][j]=0;
    dp[0][0]=1;
    rep(i,0,m+n)
    rep(j,0,m+n)
    {
        if(i&&i<=n+j)dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
        if(j&&j<=m+i)dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
    }
    return dp[n+m][n+m]%mod;
}
int main()
{
    while(~RII(n,m))printf("%lld\n",sol());
}
View Code

 

转载于:https://www.cnblogs.com/bxd123/p/11211516.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值