https://codeforces.com/problemset/problem/1288/Cios
Examplesc++
input数组
2 2
outputui
5
inputspa
10 1
outputcode
55
inputci
723 9
outputget
157557417
Noteinput
In the first test there are 5 suitable arrays:it
题目大意:
给定一个数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; }