Push Button II

题目1 : Push Button II

时间限制:10000ms

单点时限:1000ms

内存限制:256MB

描述

There are N buttons on the console. Each button needs to be pushed exactly once. Each time you may push several buttons simultaneously.

Assume there are 4 buttons. You can first push button 1 and button 3 at one time, then push button 2 and button 4 at one time. It can be represented as a string "13-24". Other pushing way may be "1-2-4-3", "23-14" or "1234". Note that "23-41" is the same as "23-14".

Given the number N your task is to find the number of different valid pushing ways.

输入

An integer N. (1 <= N <= 1000)

输出

Output the number of different pushing ways. The answer would be very large so you only need to output the answer modulo 1000000007.

样例输入

3

样例输出

13

f[i][j]表示1~i分j组按完,总共有多少种方案

import java.util.Scanner;

public class Main {
    final static long mod = 1000000007;

    public static void main (String[] arg){
        Scanner in = new Scanner(System.in);
        while (in.hasNext()){
            int num = in.nextInt();
            if (num >= 1 && num <= 1000) {
                long count = 0;
                long[][] step = new long[num][num];
                for (int i = 0;i < num;i++){
                    for (int j = 0; j < num; j++){
                        if (i < j) {
                            step[i][j] = 0;
                        } else if (j == 0) {
                            step[i][j] = 1;
                        } else if (i == 1 && j == 1) {
                            step[i][j] = 2;
                        } else  {
                            step[i][j] = (step[i - 1][j] * (j + 1) + step[i - 1][j - 1] * (j + 1)) % mod;
                        }
                        if (i == num - 1) {
                            count = (count + step[i][j]) % mod;
                        }
                    }
                }

                System.out.println(count);
            }

        }
    }
}
import java.util.*;


public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        long[] dp=new long[n+1];
        dp[1]=1;
        for (int i = 2; i <=n ; i++) {
            for (int j = i; j >0 ; j--) {
                dp[j]=(dp[j]*j+dp[j-1]*j)%1000000007;
            }
        }
        long sum=0;
        for (int i = 1; i <=n ; i++) {
            sum=(sum+dp[i])%1000000007;
        }
        System.out.println(sum);
    }
}
#include <iostream>
#include <stdio.h>
using namespace  std;
#define LL long long
const int mod = 1e9+7;
LL dp[1111][1111];

int main()
{
	int n;
	cin>>n;
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=i;j++){
			dp[i][j]=dp[i-1][j]*j+dp[i-1][j-1]*j;
			dp[i][j]%=mod;
		}
	}
	LL ans=0;
	for(int i=1;i<=n;i++)
		ans=(ans+dp[n][i])%mod;
	cout<<ans<<endl;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值