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遞推即可。
代碼如下:
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的Two Arrays(DP递推)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Yet Another Meme Pro
- 下一篇: Minimax Problem(二分+二