HDU_2604Queuing
2016-03-22 20:28
351 查看
引用大牛的解释:
用f(n)表示n个人满足条件的结果,那么如果最后一个人是m的话,那么前n-1个满足条件即可,就是f(n-1);
Total Submission(s): 4142 Accepted Submission(s): 1844
[align=left]Problem Description[/align]
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.
![](http://acm.hdu.edu.cn/data/images/C154-1005-1.jpg)
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.
[align=left]Input[/align]
Input a length L (0 <= L <= 10 6) and M.
[align=left]Output[/align]
Output K mod M(1 <= M <= 30) where K is the number of E-queues with length L.
[align=left]Sample Input[/align]
3 8
4 7
4 8
[align=left]Sample Output[/align]
6
2
1
[align=left]Author[/align]
WhereIsHeroFrom
[align=left]Source[/align]
HDU 1st “Vegetable-Birds Cup” Programming Open
Contest
[align=left]Recommend[/align]
lcy | We have carefully selected several similar problems for you: 1588 2606 2276 2603 3117
用f(n)表示n个人满足条件的结果,那么如果最后一个人是m的话,那么前n-1个满足条件即可,就是f(n-1);
如果最后一个是f那么这个还无法推出结果,那么往前再考虑一位:那么后三位可能是:mmf, fmf, mff, fff,其中fff和fmf不满足题意所以我们不考虑,但是如果是
mmf的话那么前n-3可以找满足条件的即:f(n-3);如果是mff的话,再往前考虑一位的话只有mmff满足条件即:f(n-4)
所以f(n)=f(n-1)+f(n-3)+f(n-4),递推会跪,可用矩阵快速幂
构造一个矩阵
Queuing
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4142 Accepted Submission(s): 1844
[align=left]Problem Description[/align]
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.
![](http://acm.hdu.edu.cn/data/images/C154-1005-1.jpg)
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.
[align=left]Input[/align]
Input a length L (0 <= L <= 10 6) and M.
[align=left]Output[/align]
Output K mod M(1 <= M <= 30) where K is the number of E-queues with length L.
[align=left]Sample Input[/align]
3 8
4 7
4 8
[align=left]Sample Output[/align]
6
2
1
[align=left]Author[/align]
WhereIsHeroFrom
[align=left]Source[/align]
HDU 1st “Vegetable-Birds Cup” Programming Open
Contest
[align=left]Recommend[/align]
lcy | We have carefully selected several similar problems for you: 1588 2606 2276 2603 3117
相关文章推荐
- POJ 3080 Blue Jeans
- request获取表单元素
- poj-3094-quicksum
- IOS开发之UIPickerView
- View requires API level 21 (current min is 15): <Toolbar>
- 修改UILabel的行间距
- [Angular 2] Build a select dropdown with *ngFor in Angular 2
- QuerySyntaxException: unexpected token: user_id near line 1, column 29 [from model.Demand d where d
- iOS开发之UITextView,设置textView的行间距及placeholder
- PKIX path building failed
- UESTC 1012 Ladygod (多校联盟3)
- UIButton - 设置图片及文字、文字左对齐
- easyui.min.js 报错rows is undefined
- java中的goto,const,ttrue,false,null
- 【优先队列】HDU1509Windows Message Queue
- java中queue的使用
- iOS开发—UILable详解
- UESTC 1271 Search gold (DP,多校联盟3)
- 【转】Android UI开发第三十一篇——Android的Holo Theme
- android SpannableStringBuilder