Codeforce 1288C. Two Arrays(DP组合数学,n个数选择m个数,单调不递减个数,排列组合打表N*N)
2020-08-29 21:37
381 查看
https://codeforces.com/problemset/problem/1288/C
Examples
input
2 2
output
5
input
10 1
output
55
input
723 9
output
157557417
Note
In the first test there are 5 suitable arrays:
- a=[1,1],b=[2,2]
- a=[1,2],b=[2,2]
- a=[2,2],b=[2,2]
- a=[1,1],b=[2,1]
- a=[1,1],b=[1,1]
题目大意:
给定一个数n和一个数m,让构建两个数组a和b满足条件,
1.数组中所有元素的取值在1~n之间,a和b数组长度是m。2. a数组是单调不递减的,b数组是单调不递增 3. 任意的位置i,有ai<=bi
问你有多少对这样的数组
思路:
从n个数中任选m个数,这m个数从小到大排列,且可重复选取的方案数为C(n+m-1,m)
转化为代码:
#include<bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 10001; int dp[21][1001]; int main() { //freopen("in.txt", "r", stdin); ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; m *= 2; dp[1][0] = 1; for (int i = 1; i <= m; ++i) for (int j = 1; j <= n; ++j) dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] ) % mod; long long ans = 0; for (int i = 1; i <= n; ++i) ans = (ans + dp[m][i]) % mod; cout << ans; }
相关文章推荐
- HDOJ 1799 循环多少次? (排列组合+打表)
- python 生成排列、组合以及选择
- [排列组合 + 分段打表] 51nod 算法马拉松25 A. 二分答案
- 穷举搜索:选择物品的排列组合,每个物品都——可选、不选
- 排列组合Leetcode Combinations
- USTC OJ — 1008 Word Amalgamation(组合数学,全排列)
- 输出1,2,2,3,4,5的所有排列组合,4不能在第三位,3和5不能相邻
- 祝福:新春新年大吉大利。问鼎天下,谁与争锋。非递归非交换非转数组非无序全排列组合算法,诚邀比、测、评。
- Java实现数组元素的排列组合
- Python 字符串和数字的排列组合,无重复
- MATLAB中常用的排列、组合、阶乘函数
- 输出N个数中取M个数的所有组合,排列情况
- C语言如何打印一个数组排列组合?
- 排列组合
- 高效率的排列组合算法
- 51nod 40 选择子序列 单调栈+DP
- 排列组合问题的通用算法
- 第三章 排列与组合
- SPOJ - AMR11H Array Diversity (水题排列组合或容斥)
- 排列组合中关于捆绑法、插空法、插隔板法的应用