题目链接

传送门

思路

首先我们知道\('A'\)在放了\(n\)个位置里面是没有约束的,\('B'\)在放了\(m\)个位置里面也是没有约束的,其他情况见下面情况讨论。

\(dp[i][j]\)表示放了\(i\)个\('A'\)和\(j\)个\('B'\)的方案数,然后考虑转移到下一个状态:

  • 如果\(i\leq n\),那么\('A'\)可以随意放;
  • 如果\(j\leq m\),那么\('B'\)可以随意放;
  • 如果\(i> n\),那么要放\('A'\)需要放了\('A'\)后多余的\('A'\)前面要有\('B'\)和它匹配,也就是说\(n-i-1\leq j\);
  • 如果\(j>m\),那么要放\('B'\)需要放了\('B'\)后多余的\('B'\)前面有\('A'\)和它匹配,也就是说\(n-j-1\leq i\)。

代码实现如下

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int n, m;
LL dp[2007][2007]; int main() {
while(~scanf("%d%d", &n, &m)) {
for(int i = 0; i <= n + m; ++i) {
for(int j = 0; j <= n + m; ++j) {
dp[i][j] = 0;
}
}
dp[0][0] = 1;
for(int i = 0; i <= n + m; ++i) {
for(int j = 0; j <= n + m; ++j) {
if(i < n + j) dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod;
if(j < m + i) dp[i][j+1] = (dp[i][j+1] + dp[i][j]) % mod;
}
}
printf("%lld\n", dp[n+m][n+m]);
}
return 0;
}

最新文章

  1. [ZigBee] 6、ZigBee基础实验——定时器3和定时器4(8 位定时器)
  2. jquery版瀑布流
  3. sitemesh学习笔记(2)
  4. 夺命雷公狗---Thinkphp----11之管理员的增删改查的完善
  5. StringReplace用法
  6. C++函数学习笔记
  7. android开发之单点触摸
  8. mongodb exception in initAndListen: 12596 old lock file, terminating 解决方法
  9. Hibernate学习笔记--映射配置文件详解
  10. 【Xamarin开发IOS-IOS生命周期】
  11. ios 读取通讯录数据
  12. view import symbols
  13. jmake 编译当前目录c/c++单文件 指定文件 可加选项
  14. CFILE追加写入文件
  15. smartGWT DataSource数据动态加载
  16. Leetcode_38_count-and-say
  17. requestAnimationFrame 知多少?
  18. 《剑指offer》丑数
  19. angular ViewChild ContentChild 系列的查询参数
  20. pandas 基础操作 更新

热门文章

  1. 【tensorflow-v2.0】如何查看模型的输入输出流的属性
  2. 【并行计算-CUDA开发】OpenACC与OpenHMPP
  3. adb devices命令链接设备失败 解决办法
  4. Vue 动态路由的实现以及 Springsecurity 按钮级别的权限控制
  5. Python之路【第十八篇】:前端HTML
  6. Linux下嵌入式Web服务器BOA和CGI编程开发
  7. 用python批量添加保护站点
  8. git如何支持doc文档
  9. java之hiberante之集合映射之list映射
  10. C#泛型集合之——队列与堆栈