Problem:
Score : 800 points

Problem Statement

Find the number, modulo 998244353, of sequences of length N consisting of 0, 1 and 2 such that none of their contiguous subsequences totals to X.

Constraints

1 \leq N \leq 3000

1 \leq X \leq 2N

N and X are integers.

Input

Input is given from Standard Input in the following format:

N X

Output

Print the number, modulo 998244353, of sequences that satisfy the condition.

Sample Input 1

3 3

Sample Output 1

14

14 sequences satisfy the condition: (0,0,0),(0,0,1),(0,0,2),(0,1,0),(0,1,1),(0,2,0),(0,2,2),(1,0,0),(1,0,1),(1,1,0),(2,0,0),(2,0,2),(2,2,0) and (2,2,2).

Sample Input 2

8 6

Sample Output 2

1179

Sample Input 3

10 1

Sample Output 3

1024

Sample Input 4

9 13

Sample Output 4

18402

Sample Input 5

314 159

Sample Output 5

459765451

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>
#include <ctime>
#include <string>
#include <iostream>
#include <bitset>
#define PII pair <int, int>
#define PPI pair <PII, int>
#define x first
#define y second
#define P 998244353

using namespace std;

typedef long long ll;

int N, X;

int F[2][6010][2][2], G[3010][6010], C[6010][6010];

void add(int &x, int y) {
    x = (x + y) % P;
}
int main() {
    scanf("%d%d", &N, &X);
    G[0][0] = 1;
    int ans = 0;
    for(int i = 0; i < N; i++)
        for(int j = 0; j < X; j++) {
            add(G[i + 1][j], G[i][j]);
            add(G[i + 1][j + 1], G[i][j]);
            add(G[i + 1][j + 2], G[i][j]);
        }
    if(X % 2 == 1) {
        for(int i = 0; i <= N; i++)
            for(int j = 0; j <= i; j++)
                C[i][j] = !j ? 1 : (C[i - 1][j - 1] + C[i - 1][j]) % P;
        for(int i = X; i <= N; i++)
            add(ans, C[N][i]);
    }
    for(int i = 0; i < X; i++) add(ans, G[N][i]);
    int a = 0, b = 1;
    memset(F, 0, sizeof F);
    F[a][0][0][1 - 1] = 1;
    for(int i = 0; i < N - 1; i++, swap(a, b)) {
        memset(F[b], 0, sizeof F[b]);
        for(int o = 0; o < X; o++)
            for(int s = 0; s < 2; s++)
                for(int k = 1; k < 3; k++) if(F[a][o][s][k - 1])
                    for(int l = 0; l + k < 3; l++) {
                        add(F[b][o + l][s][k + l - 1], F[a][o][s][k - 1]);
                        if(l) add(F[b][o + l][!s][l - 1], F[a][o][s][k - 1]);
                    }
        for(int o = 1; o < X; o++)
            for(int k = 1; k < 3; k++)
                for(int l = 1; l + k < 3; l++)
                    add(ans, 1LL * F[b][o][1][k - 1] * G[N - i - 2][X - 1 - o - l] % P);
    }
    printf("%d\n", (ans % P + P) % P);
    return 0;
}