Problem:
Score : 1200 points

Problem Statement

Snuke has decided to play with N cards and a deque (that is, a double-ended queue).
Each card shows an integer from 1 through N, and the deque is initially empty.

Snuke will insert the cards at the beginning or the end of the deque one at a time, in order from 1 to N.
Then, he will perform the following action N times: take out the card from the beginning or the end of the deque and eat it.

Afterwards, we will construct an integer sequence by arranging the integers written on the eaten cards, in the order they are eaten. Among the sequences that can be obtained in this way, find the number of the sequences such that the K-th element is 1. Print the answer modulo 10^{9} + 7.

Constraints

1 ≦ K ≦ N ≦ 2{,}000

Input

The input is given from Standard Input in the following format:

N K

Output

Print the answer modulo 10^{9} + 7.

Sample Input 1

2 1

Sample Output 1

1

There is one sequence satisfying the condition: 1,2. One possible way to obtain this sequence is the following:

Insert both cards, 1 and 2, at the end of the deque.

Eat the card at the beginning of the deque twice.

Sample Input 2

17 2

Sample Output 2

262144

Sample Input 3

2000 1000

Sample Output 3

674286644

Solution in C++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 2010
const int p=1e9+7;
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
int n,K,f[maxn];
int add(int x,int y)
{
	return (x+y)%p;
}
int mul(int x,int y)
{
	return 1ll*x*y%p;
}
int fpow(int x,int y)
{
	int res=1;
	while(y)
	{
		if(y&1)
			res=mul(res,x);
		x=mul(x,x);
		y>>=1;
	}
	return res;
}
int main()
{
	read(n,K);
	f[n+1]=1;
	for(int i=1;i<=K;i++)
	{
		for(int j=n;j>=1;j--)
		{
			if(n-j+1>=i)
				f[j]=add(f[j],f[j+1]);
			else
				f[j]=0;
		}
	}
	printf("%d\n",mul(f[1],fpow(2,n-K-1)));
    return 0;
}