hihocoder#1444 : Push Button II(DP)

来源:互联网 发布:mac双系统分区大小 编辑:程序博客网 时间:2024/05/21 00:00

时间限制: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
思路:d[i]表示还剩下i个按钮时的合法方案数。

#include<bits/stdc++.h>using namespace std;const int MOD=1000000007;long long d[1001],c[1001][1001];long long dfs(long long n){    if(n==0)return 1;    if(d[n])return d[n];    for(int i=1;i<=n;i++)d[n]=(d[n]+c[n][i]*dfs(n-i)%MOD)%MOD;    //printf("d[%lld]=%lld\n",n,d[n]);    return d[n];}void init(){    memset(c,0,sizeof c);    c[0][0]=1;    for(int i=1;i<=1000;i++)    {        c[i][0]=1;        for(int j=1;j<=i;j++)c[i][j]=(c[i-1][j-1]+c[i-1][j])%MOD;    }}int main(){    init();    long long n;    cin>>n;    memset(d,0,sizeof d);    cout<<dfs(n)<<endl;    return 0;}




原创粉丝点击