日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Two Arrays(DP递推)

發布時間:2023/12/15 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Two Arrays(DP递推) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

You are given two integers nn and mm. Calculate the number of pairs of arrays (a,b)(a,b) such that:

the length of both arrays is equal to mm;
each element of each array is an integer between 11 and nn (inclusive);
ai≤biai≤bi for any index ii from 11 to mm;
array aa is sorted in non-descending order;
array bb is sorted in non-ascending order.
As the result can be very large, you should print it modulo 109+7109+7.

Input
The only line contains two integers nn and mm (1≤n≤10001≤n≤1000, 1≤m≤101≤m≤10).

Output
Print one integer – the number of arrays aa and bb satisfying the conditions described above modulo 109+7109+7.

Examples
Input
2 2
Output
5
Input
10 1
Output
55
Input
723 9
Output
157557417
Note
In the first test there are 55 suitable arrays:

a=[1,1],b=[2,2]a=[1,1],b=[2,2];
a=[1,2],b=[2,2]a=[1,2],b=[2,2];
a=[2,2],b=[2,2]a=[2,2],b=[2,2];
a=[1,1],b=[2,1]a=[1,1],b=[2,1];
a=[1,1],b=[1,1]a=[1,1],b=[1,1].
構造兩個數組,有幾個要求。
①長度為m。并且數組中的數字范圍為1~n。
②a數組是非遞減數組,b數組是非遞增數組。
③對于兩個數組的相同位置的數字,ai<bi。
問能構造出幾個這樣的數組來。
思路:一開始想的很復雜,無從下手。試想一下,如果同時考慮a和b兩個數組,這樣的話,要考慮兩個方面,不太好寫。如果把a數組正序排列,b數組倒序排列,然后組合起來,這樣的話,不就是一個長度為2m的非遞減數組了嗎。這樣就轉化成了長度為2m,數組范圍1~n的非遞減數組有多少個了。DP遞推即可。
代碼如下:

#include<bits/stdc++.h> #define ll long long #define mod 1000000007 using namespace std;const int maxx=1e3+100; int n,m; ll dp[21][maxx];int main() {while(cin>>n>>m){memset(dp,0,sizeof(dp));for(int i=1;i<=n;i++) dp[1][i]=1ll;for(int i=2;i<=2*m;i++){for(int j=1;j<=n;j++){for(int k=1;k<=j;k++){dp[i][j]=(dp[i][j]+dp[i-1][k])%mod;}}}ll ans=0;for(int i=1;i<=n;i++) ans=(ans+dp[2*m][i])%mod;cout<<ans<<endl;} }

努力加油a啊,(o)/~

總結

以上是生活随笔為你收集整理的Two Arrays(DP递推)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。