Description
There are $n$ light(s) in a row.These lights are numbered $1$ to $n$ from left to right.One of the lights are switched on.I wants to switch all the lights on.
At each step I can switch a light on(this light should be switched off at that moment)if there's at least one “very close” light which is already switched on.
More exactly: when No.$i$ light(this light is switched on now),No.$j$ light can be switched on(this light is switched off now) if and only if $|i-j|<=2$.
I knows the initial state of lights and I wonder how many different ways there exist to switch all the lights on.
Please find the required number of ways modulo $1000000007 (10^9+7)$.
Input
The first line of the input contains two integers $n$ and $m$ where $n$ is the number of lights in the sequence and No.$m$ light are initially switched on,$(1<=n<=1000,1<=m<=n)$.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo $1000000007 (10^9+7)$.
Sample Input
3 1
Sample Output
2
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
ll c[1111][1111],f[1111];
int main()
{
int i,j,n,m;
f[0]=1;f[1]=1;
f[2]=2;
for(n=3;n<=1000;n++) f[n]=(f[n-1]+f[n-2]*(n-1)%mod)%mod;
for(i=0;i<=1000;i++) {
c[0][i]=1;
c[i][i]=1;
}
for(i=1;i<=1000;i++) {
for(j=1;j<i;j++){
c[j][i]=(c[j-1][i-1]+c[j][i-1])%mod;
// cout<<i<<" "<<j<<" "<<c[j][i]<<endl;
}
}
while(cin>>n>>m) {
ll ans=0;
ans=f[m-1]*f[n-m]%mod*c[m-1][n-1]%mod;
cout<<ans<<endl;
}
return 0;
}