Dynamic Programming again!
There are a lot of state, so, the main point is how to classify them clearly.
dp[i][j][0]: as the number of different methods to divide 2 * i chocolate grid into j part and last two grid in i-th column are in the same connected component.
dp[i][j][1]: as the number of different methods to divide 2 * i chocolate grid into j part and last two grid in i-th column are in different connected component.
Then we classify state into two situations and each has some sub-situations.
And coding.
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <queue>
#include <stack>
using namespace std;
#define MS(c, a) memset(c, a, sizeof c)
#define Rep(c, a, b) for (int c = (a); c < (b); c++)
#define Nre(c, a, b) for (int c = (a); c > (b); c--)
#define MAXN (2020)
#define MOD (100000007)
typedef long long LL;
LL dp[MAXN][MAXN][3];
int n, k;
int main()
{
dp[1][1][0] = dp[1][2][1] = dp[1][1][2] = dp[1][2][2] = 1;
Rep(i, 2, 1010) Rep(j, 1, i * 2 + 1)
{
int k = i - 1;
dp[i][j][0] = (dp[k][j][0] + dp[k][j - 1][2] + 2 * dp[k][j][1]) % MOD;
dp[i][j][1] = (2 * dp[k][j - 1][2] + dp[k][j][1]) % MOD;
if (j > 2) dp[i][j][1] = (dp[i][j][1] + dp[k][j - 2][2]) % MOD;
dp[i][j][2] = (dp[i][j][0] + dp[i][j][1]) % MOD;
}
int T;
scanf("%d", &T);
while (T--)
{
scanf("%d%d", &n, &k);
printf("%lld\n", dp[n][k][2]);
}
return 0;
}