2 * N 的方块被划分为 M 块(每一块都不一样),有多少种不同的分法。
#include <iostream>
using namespace std;
#define MERGE 1
#define CUT 0
#define MOD 100000007
int DP[1010][2020][2]= {0};
int test;
int n, m, ans;
int main()
{
DP[1][2][CUT] = 1;
DP[1][1][MERGE] = 1;
for( int col = 1; col <= 1002; ++col )
{
for( int num = 1; num <= col * 2; ++num )
{
DP[col + 1][num][MERGE] = ( DP[col + 1][num][MERGE] +
DP[col][num][MERGE] +
DP[col][num][CUT] * 2 ) % MOD;
DP[col + 1][num + 1][MERGE] = ( DP[col + 1][num + 1][MERGE] +
DP[col][num][MERGE] +
DP[col][num][CUT] ) % MOD;
DP[col + 1][num][CUT] = ( DP[col + 1][num][CUT] +
DP[col][num][CUT] ) % MOD;
DP[col + 1][num + 1][CUT] = ( DP[col + 1][num + 1][CUT] +
DP[col][num][MERGE] * 2 +
DP[col][num][CUT] * 2 ) % MOD;
DP[col + 1][num + 2][CUT] = ( DP[col + 1][num + 2][CUT] +
DP[col][num][MERGE] +
DP[col][num][CUT] ) % MOD;
}
}
cin >> test;
while( test-- )
{
cin >> n >> m;
ans = ( DP[n][m][MERGE] + DP[n][m][CUT] ) % MOD;
cout << ans << endl;
}
return 0;
}