hihocoder#1444 : Push Button II(DP)
来源:互联网 发布:mac双系统分区大小 编辑:程序博客网 时间:2024/05/21 00:00
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
- 样例输入
3
- 样例输出
13
描述
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.
#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;}
阅读全文
1 0
- hihocoder#1444 : Push Button II(DP)
- hihocoder #1482 : 出勤记录II dp
- [Win32SDK基本]Button Control(1)Push Button 和 BM_SETIMAGE
- hihocoder 1076 与链(DP)
- hihoCoder#1037 : 数字三角形(DP)
- hihocoder 1055 刷油漆(树形dp)
- hihocoder-1055 刷油漆(树形DP)
- hihoCoder 1037 数字三角形(基础dp)
- hihocoder #1043 : 完全背包 (DP)
- hihoCoder 交错和 (数位DP)
- hihocoder #1318 : 非法二进制数(dp)
- hihocoder 1532 最美和弦 (dp)
- hihocoder 1033 交错和 (数位dp)
- hihocoder#1506 : 投掷硬币(概率DP)
- hihocoder#1239 : Fibonacci(递推DP)
- hihoCoder#1608 : Jerry的奶酪(dp)
- hihoCoder 1338 : A Game(dp)
- hihocoder#1664 : 01间隔方阵(DP)
- Ztree树节点应用
- 【mysql 体系结构】了解MySQL体系结构
- jquery.bigautocomplete.js首次获取焦点触发搜索(类似百度首次的搜索历史)
- JZOJsenior3498.【NOIP2013模拟联考14】图形变换(transform)
- 【Python刷题*计算客】A+B+C问题
- hihocoder#1444 : Push Button II(DP)
- ECSHOP模板开发教程完全攻略
- 轻量化autolayout布局框架,支持多级映射
- C语言文件操作相关函数
- 2、Vim常用操作
- 网易游戏笔试题(2) 20171209
- android 开发不得不了解的adb
- 他竟然只用25万美元换来苹果1/3的股票?
- Python字符串、文件与目录操作