B - Open the lightings (组合数学)


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;
} 














评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值