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;
const ll MOD=1000000007;

ll n,a,b;
ll x[5002];
void x_init(){
	ll dp[5005][2];
	dp[1][0]=1;
	dp[1][1]=0;
	for(int i=1;i<=a;i++){
		dp[i+1][0]+=dp[i][0];
		if(dp[i+1][0]>=MOD)dp[i+1][0]-=MOD;
		if(i+b<=a){
			dp[i+b][1]+=dp[i][0];
			if(dp[i+b][1]>=MOD)dp[i+b][1]-=MOD;
		}
		dp[i+1][0]+=dp[i][1];
		if(dp[i+1][0]>=MOD)dp[i+1][0]-=MOD;
		dp[i+1][1]+=dp[i][1];
		if(dp[i+1][1]>=MOD)dp[i+1][1]-=MOD;
	}
	for(int i=1;i<=a;i++){
		x[i]=dp[i][0];
		//cout<<i<<":"<<x[i]<<endl;
	}
}

int main(){
	cin>>n>>a>>b;
	if(a<b)swap(a,b);
	x_init();
	
	ll dp[5002][2]={};
	for(int i=1;i<=a-1;i++){
		dp[i][0]=x[i+1];
	}
	for(int i=1;i<=b-1;i++){
		dp[i][1]=1;
	}
	for(int i=1;i<=n-1;i++){
		for(int j=1;j<=b-1;j++){
			if(i+j<=n){
				dp[i+j][1]+=dp[i][0];
				if(dp[i+j][1]>=MOD)dp[i+j][1]-=MOD;
			}
		}
		for(int j=1;j<=a-1;j++){
			if(i+j<n){
				dp[i+j][0]+=dp[i][1]*x[j];
				dp[i+j][0]%=MOD;
			}
			else if(i+j==n){
				dp[i+j][0]+=dp[i][1]*x[j+1];
				dp[i+j][0]%=MOD;
			}
		}
	}
	ll ret=1;
	for(int i=0;i<n;i++){
		ret*=2;
		ret%=MOD;
	}
	ret+=MOD-dp[n][0];
	ret+=MOD-dp[n][1];
	cout<<ret%MOD<<endl;
	//cout<<(dp[n][0]+dp[n][1])%MOD<<endl;
}