zoukankan      html  css  js  c++  java
  • 牛客第一场 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
    ",sol());
    }
    View Code
  • 相关阅读:
    setCookie
    EF getCookie
    EF
    Dapper修改
    Dapper显示
    Dapper上传图片
    Dapper存储过程分页
    Azure Function(.Net Cor框架)读取配置文件
    .Net Core3.1中出现AssemblyInfo特性重复
    YAML配置文件 基础学习
  • 原文地址:https://www.cnblogs.com/bxd123/p/11211516.html
Copyright © 2011-2022 走看看