UESTC 1268 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


这题只要把灯拆成左边和右边就行了,左边的情况是没办法影响到右边的,所有两边是独立的。

那么只要单独计算当f[i]前i个灯全量的方案数就行了,这个可以很快找到规律递推出来,然后是两边

的合并,因为互相独立,点i盏灯,右边点j盏灯的全部组合就相当于往i+1个盒子里放j个相同的球的情况

直接预处理出f和组合数就好了。

#include<iostream>  
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
const int maxn = 1e3 + 5;
const int base = 1e9 + 7;
const int low(int x){ return x&-x; }
int T, n, m;
LL f[maxn], c[maxn][maxn];


int main(){
	//scanf("%d", &T);
	f[0] = f[1] = 1;
	for (int i = 2; i < 1000; i++) f[i] = ((LL)(i - 1)*f[i - 2] + f[i - 1]) % base;
	for (int i = 1; i < 1000; i++)
	{
		c[i][0] = c[i][i] = 1;
		for (int j = 1; j < i; j++)
		{
			c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % base;
		}
	}
	while (~scanf("%d%d", &n, &m))
	{
		int x = m - 1, y = n - m;
		printf("%lld\n", c[n - 1][y] * f[x] % base*f[y] % base);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值