标签:ash pie int for txt targe target ref copy
题目链接:http://codeforces.com/problemset/problem/1288/C
You are given two integers nn and mm. Calculate the number of pairs of arrays (a,b)(a,b) such that:
As the result can be very large, you should print it modulo 109+7109+7.
The only line contains two integers nn and mm (1≤n≤10001≤n≤1000, 1≤m≤101≤m≤10).
Print one integer – the number of arrays aa and bb satisfying the conditions described above modulo 109+7109+7.
2 2
5
10 1
55
723 9
157557417
In the first test there are 55 suitable arrays:
题目大意:
给定一个数n和一个数m,让构建两个数组a和b满足条件,
1.数组中所有元素的取值在1~n之间,a和b数组长度是m。2. a数组是单调不递减的,b数组是单调不递增 3. 任意的位置i,有ai<=bi
问你有多少对这样的数组
思路:一直在想组合数学怎么做,感觉很麻烦,很多种情况,就没写了。 dp其实可以做
a数组是单调不递减 b数组是单调不递增 ,如果我们把b数组反过来呢 接在a数组的后面,我们会得到一个长度为2*M的单调不递减的数组
是的,那么我们只要求长度为2*M的单调不递减的数组就行了
得到状态转移方程:
dp[i][j]表示第i个位置可以放 大于等于 j 的方案数 ,那么转移方程就是 dp[i][j] = dp[i-1][j] + dp[i][j+1]
看代码:
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<vector> #include<stack> #include<map> #include<queue> using namespace std; typedef long long LL; #define sc1(a) scanf("%lld",&a) #define pf1(a) printf("%lld\n",a) #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 const int INF=1e9+7; const int maxn=1e3+5; const int maxm=10+5; const int maxv=1e6+5; const int mod=1e9+7; const int ba=3e5; LL dp[maxm<<1][maxn]; int main() { // freopen("in.txt","r",stdin); LL N,M;sc1(N);sc1(M); for(int i=1;i<=N;i++) dp[1][i]=1; for(int i=2;i<=M*2;i++) { for(int j=N;j>=1;j--) { dp[i][j]=(dp[i-1][j]+dp[i][j+1])%mod; } } LL ans=0; for(int i=1;i<=N;i++) ans=(ans+dp[2*M][i])%mod; pf1(ans); return 0; } /** */
Two Arrays CodeForces - 1288C(单调不递减数组个数)
标签:ash pie int for txt targe target ref copy
原文地址:https://www.cnblogs.com/caijiaming/p/12256489.html