HDU 2604 Queuing 递推
来源:互联网 发布:mac u盘启动盘制作 编辑:程序博客网 时间:2024/06/05 10:14
Queuing
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2506 Accepted Submission(s): 1179
Problem Description
Queues and Priority Queues are data structures which are known to most computer scientists. The Queue occurs often in our daily life. There are many people lined up at the lunch time.
Now we define that ‘f’ is short for female and ‘m’ is short for male. If the queue’s length is L, then there are 2L numbers of queues. For example, if L = 2, then they are ff, mm, fm, mf . If there exists a subqueue as fmf or fff, we call it O-queue else it is a E-queue.
Your task is to calculate the number of E-queues mod M with length L by writing a program.
Your task is to calculate the number of E-queues mod M with length L by writing a program.
Input
Input a length L (0 <= L <= 10 6) and M.
Output
Output K mod M(1 <= M <= 30) where K is the number of E-queues with length L.
Sample Input
3 84 74 8
Sample Output
621
/*HDU 2604 递推 转载别人的 前四位我们可以算出d[1]=2,d[2]=4,d[3]=6,d[4]=9.一个合法串可以由两个较短的合法串组成就以d[n]为例:主要注意不能重复 1、n-1个字符的时候: +m2、n-2: 只能+mm,会和n-1重复,所以不考虑n-23、n-3: +mmf4、n-4: +mmff5、n-5: 如果是+mmffm,会与n-1重复,+mmmff会与n-4重复,+mmmmf会与n-3重复(不考虑)dp[n]=dp[n-1]+dp[n-3]+dp[n-4]n<10^6 m<=30 用打表可以做 [刚刚开始直接用int敲的代码,果断MLE了。。。改成char试试 - -就过了]*/#include <iostream>using namespace std;#define N 1000001#define M 30char node[N][M];//二维数组表示的是数n mod m; void init(){ int i,j; for(i=1;i<=M;i++) { node[1][i]=2%i; node[2][i]=4%i; node[3][i]=6%i; node[4][i]=9%i; for (j=5;j<=N;j++) { node[j][i]=(node[j-1][i]+node[j-3][i]+node[j-4][i])%i; } }}int main(){ init(); int n,m; while (~scanf("%d%d",&n,&m)) { printf("%d\n",node[n][m]); } return 0;}
0 0
- HDU 2604 Queuing 递推
- HDU 2604 Queuing 递推
- hdu 2604 Queuing(矩阵乘法+递推)
- hdu 2604 Queuing(状态压缩递推,矩阵)
- hdu 2604 Queuing(矩阵优化递推公式)
- HDU 2604-Queuing(递推+矩阵快速幂)
- HDU 2604 Queuing (递推+矩阵快速幂)
- hdu 2604 Queuing 递推+矩阵快速幂
- hdu 2604 Queuing【递推+矩阵快速幂】
- HDU 2604 Queuing [递推]【矩阵快速幂】
- HDU 2604-Queuing(递推+构造矩阵)
- HDU 2604 Queuing (递推+ 矩阵快速幂)
- hdu 2064 Queuing (递推)
- hdu 2604 Queuing 递推/DP 矩阵快速幂 Trie数辅助
- 【HDU】2604 - Queuing(递推 & 思维 & 矩阵构造 & 快速幂)
- 【hdu 4062】Queuing 【思维+递推+矩阵快速幂】
- HDOJ 2604 Queuing (递推+矩阵快速幂)
- hdu 2604 Queuing
- 【甘道夫】Hadoop2.2.0环境使用Sqoop-1.4.4将Oracle11g数据导入HBase0.96,并自动生成组合行键
- 用django做一个午餐账单管理小程序
- 未付初值,引发不确定后续错误一例
- http 压力测试工具
- Android图片的一些操作
- HDU 2604 Queuing 递推
- Android中Toast的用法简介
- How to get your all bugs resolved without any ‘Invalid bug’ label?
- 自定义JS字符串全局替换函数replaceAll
- HDU 1003 Max Sum 最大连续上升和
- Android的ScrollView中添加自定义View
- HDU 1824 Let's go home(2-SAT)
- 企业数通知识系列之四--DHCP v6介绍
- 深圳—驾考