hdoj.1297 Children’s Queue【大数+排列组合】 2015/08/06
来源:互联网 发布:淘宝里食品类目划分 编辑:程序博客网 时间:2024/06/10 18:59
Children’s Queue
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12414 Accepted Submission(s): 4051
Problem Description
There are many students in PHT School. One day, the headmaster whose name is PigHeader wanted all students stand in a line. He prescribed that girl can not be in single. In other words, either no girl in the queue or more than one girl stands side by side. The case n=4 (n is the number of children) is like
FFFF, FFFM, MFFF, FFMM, MFFM, MMFF, MMMM
Here F stands for a girl and M stands for a boy. The total number of queue satisfied the headmaster’s needs is 7. Can you make a program to find the total number of queue with n children?
FFFF, FFFM, MFFF, FFMM, MFFM, MMFF, MMMM
Here F stands for a girl and M stands for a boy. The total number of queue satisfied the headmaster’s needs is 7. Can you make a program to find the total number of queue with n children?
Input
There are multiple cases in this problem and ended by the EOF. In each case, there is only one integer n means the number of children (1<=n<=1000)
Output
For each test case, there is only one integer means the number of queue satisfied the headmaster’s needs.
Sample Input
123
Sample Output
124
Author
SmallBeer (CML)
Source
杭电ACM集训队训练赛(VIII)
递推公式为:f(n) = f(n-1) + f(n-2) + f(n-4)
注:人越多,组合数越大,需要大数相加
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int ch[1010][1010];int main(){ memset(ch,0,sizeof(ch)); ch[0][0] = ch[1][0] = ch[2][0] = ch[3][0] = 1; ch[0][1] = 1; ch[1][1] = 1; ch[2][1] = 2; ch[3][1] = 4; for( int i = 4 ; i <= 1000 ; ++i ){ for( int j = 1 ; j <= ch[i-1][0] ; ++j ) ch[i][j] = ch[i-1][j] + ch[i-2][j] + ch[i-4][j]; for( int j = 1 ; j <= ch[i-1][0] ; ++j ) if( ch[i][j] > 9 ){ ch[i][j+1] += ch[i][j] / 10; ch[i][j] %= 10; } ch[i][0] = ch[i][ch[i-1][0]+1] ? ch[i-1][0] + 1 : ch[i-1][0]; } int n; while( scanf("%d",&n)!=EOF ){ for( int i = ch[n][0] ; i > 0 ; --i ) printf("%d",ch[n][i]); printf("\n"); } return 0;}
0 0
- hdoj.1297 Children’s Queue【大数+排列组合】 2015/08/06
- HDOJ 题目1297Children’s Queue(递推,大数)
- HDOJ/HDU 1297 Children’s Queue(推导~大数)
- ACM--学生排队--HDOJ 1297--Children’s Queue--大数
- HDOJ 1297:Children’s Queue
- HDOJ 1297 Children’s Queue
- hdu 1297 children's queue #DP#大数
- Children’s Queue 1297 (大数)
- HDU 1297 Children’s Queue 递归+大数
- (HDOJ)Children's Queue(java大数大法好)
- ACM HDOJ 1297 (Children’s Queue)
- hdu 1297 Children’s Queue(递推+大数)
- 【大数递推】HDU 1297——Children’s Queue
- hdu 1297 Children’s Queue(大数处理)
- hdu 1297 Children’s Queue (大数加法+递推)
- HDU 1297 Children’s Queue(含整型大数模板)
- 杭电acm 1297 Children's Queue.大数加递归
- hdu 1297 Children’s Queue 递推 大数
- 指针与引用的区别
- 八大排序算法
- POJ 1114 Network
- EditText getText()方法无效
- poj1273 Drainage Ditches(最大流)
- hdoj.1297 Children’s Queue【大数+排列组合】 2015/08/06
- MSBUildToolsPath is not specified for the ToolsVersion
- 南邮 OJ 1588 简单计算器
- hdu 4521
- [易飞]设置公用参数
- iOS开发者面试必备:10个Objective-C基础面试题
- android 绘图之Path与Paint详解
- Java集合--Map、Collections和Arrays
- 什么是信息熵