Educational Codeforces Round 80 (Rated for Div. 2) C - Two Arrays(DP)
程序员文章站
2022-03-12 17:01:02
...
题意:从1~n里面选出来m个数字组成a数组,再选出来m个组成b数组,要求a非递减,b非递增,且bi>=ai
题目挺有意思(短)的,解题过程分两步:
1,说是选两个数组其实就是选出来一个长m*2的非递减数组
2,假设要从n的全排列中选出来m长的非递减数组,因为元素是可重复的,最多重复m次,其实就是相当于从下面这个矩阵中选择元素
从这个矩阵中选择元素,每行只能选择一个,枚举我们选出的k个元素的最小值为[ i , j ]位置,那么除去这个元素选择k-1个元素的方案数之和就是k个元素,如图中红色标出位置,最后就是边界,选择一个元素(最后一行)的方案数就是1。
ll mod = 1e9 + 7;
ll mem[30][2000];
int n, m;
ll dp(int i, int lst)
{
if (i == m) return 1;
ll &ret = mem[i][lst];
if (ret) return ret;
for (int j = lst; j <= n; j++)
ret += dp(i + 1, j) % mod;
return ret % mod;
}
int main()
{
cin>>n>>m;
m *= 2;
cout<<dp(0,1)%mod<<endl;
return 0;
}
推荐阅读
-
Educational Codeforces Round 85 (Rated for Div. 2) C. Circle of Monsters(前缀和 预处理 贪心)
-
Educational Codeforces Round 99 (Rated for Div. 2) C. Ping-pong
-
C. Mortal Kombat Tower(动态规划)Educational Codeforces Round 95 (Rated for Div. 2)
-
Educational Codeforces Round 88 (Rated for Div. 2)C. Mixing Water[题解](数学)
-
Educational Codeforces Round 95 (Rated for Div. 2)C. Mortal Kombat Tower【dp】
-
Educational Codeforces Round 86 (Rated for Div. 2)---C
-
Educational Codeforces Round 83 (Rated for Div. 2) D. Count the Arrays
-
codeforces Educational Codeforces Round 80 (Rated for Div. 2) D - Minimax Problem(状压)
-
Educational Codeforces Round 80 (Rated for Div. 2)
-
Educational Codeforces Round 62 (Rated for Div. 2) C