Problem:
Score : 800 points

Problem Statement

Snuke has a string x of length N.
Initially, every character in x is 0.

Snuke can do the following two operations any number of times in any order:

Choose A consecutive characters in x and replace each of them with 0.

Choose B consecutive characters in x and replace each of them with 1.

Find the number of different strings that x can be after Snuke finishes doing operations.
This count can be enormous, so compute it modulo (10^9+7).

Constraints

1 \leq N \leq 5000

1 \leq A,B \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of different strings that x can be after Snuke finishes doing operations, modulo (10^9+7).

Sample Input 1

4 2 3

Sample Output 1

11

For example, x can be 0011 or 1111 in the end, but cannot be 0110.

Sample Input 2

10 7 2

Sample Output 2

533

Sample Input 3

1000 100 10

Sample Output 3

828178524

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);

int dp[5001][2][5001][2];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int mod = 1e9+7;
    int n,a,b;
    cin>>n>>a>>b;
    if(a<b)swap(a,b);
    if(a==1||b==1){
        ll ans = 1;
        for(int i=0;i<n;i++){
            ans *= 2LL;
            ans %= mod;
        }
        cout << ans << endl;
        return 0;
    }
    dp[0][0][1][0]=1;
    dp[0][1][1][0]=1;
    for(int i=1;i<n;i++){
        for(int j=1;j<=i;j++){
            // 0 -> 0
            dp[i][0][j+1][1] += dp[i-1][0][j][1];
            dp[i][0][j+1][1] %= mod;
            if(j+1<a){
                dp[i][0][j+1][0] += dp[i-1][0][j][0];
                dp[i][0][j+1][0] %= mod;
            }
            else if(j+1==a){
                dp[i][0][j+1][1] += dp[i-1][0][j][0];
                dp[i][0][j+1][1] %= mod;
            }

            // 1 -> 1
            dp[i][1][j+1][1] += dp[i-1][1][j][1];
            dp[i][1][j+1][1] %= mod;
            if(j+1<b){
                dp[i][1][j+1][0] += dp[i-1][1][j][0];
                dp[i][1][j+1][0] %= mod;
            }
            else if(j+1==b){
                dp[i][1][j+1][1] += dp[i-1][1][j][0];
                dp[i][1][j+1][1] %= mod;
            }

            // 1 -> 0
            if(j>=b || i-j>=a || n-i>=a){
                dp[i][0][1][1] += dp[i-1][1][j][1];
                dp[i][0][1][1] %= mod;
                if(j<b){
                    dp[i][0][1][0] += dp[i-1][1][j][0];
                    dp[i][0][1][0] %= mod;
                }
            }

            // 0 -> 1
            if(j>=a || i-j>=b || n-i>=b){
                dp[i][1][1][1] += dp[i-1][0][j][1];
                dp[i][1][1][1] %= mod;
                if(j<a){
                    dp[i][1][1][0] += dp[i-1][0][j][0];
                    dp[i][1][1][0] %= mod;
                }
            }
        }
    }
    ll ans = 0;
    ll rem = 0;
    for(int i=1;i<=n;i++){
        ans += dp[n-1][1][i][1];
        ans %= mod;
        ans += dp[n-1][0][i][1];
        ans %= mod;

        rem += dp[n-1][1][i][0];
        rem += dp[n-1][0][i][0];
        rem %= mod;
    }
    // できないものも数えている。
    // 

    cout << ans << endl;
    cerr << rem << endl;
}