hdu---(2604)Queuing(矩阵快速幂)
Queuing
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2796 Accepted Submission(s): 1282
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.
4 7
4 8
2
1
- //#define LOCAL
- #include<cstdio>
- #include<cstring>
- using namespace std;
- //matrix --> ¾ØÕó
- int mat[][];
- int ans[][];
- int len,m;
- void init()
- {
- int cc[][]={
- {,,,},{,,,},
- {,,,},{,,,}};
- for(int i=;i<;i++)
- {
- for(int j=;j<;j++)
- {
- mat[i][j]=cc[i][j];
- if(i==j) ans[i][j]=;
- else ans[i][j]=;
- }
- }
- }
- void Matrix(int a[][],int b[][]) //¾ØÕóÏà³Ë
- {
- int i,j,k;
- int c[][]={};
- for(j=;j<;j++){
- for(i=;i<;i++){
- for(k=;k<;k++){
- c[j][i]=(c[j][i]+a[j][k]*b[k][i])%m;
- }
- }
- }
- for(j=;j<;j++)
- for(i=;i<;i++)
- a[j][i]=c[j][i];
- }
- void pow(int n)
- {
- while(n>)
- {
- if(n&) Matrix(ans,mat);
- n>>=;
- if(n==) break;
- Matrix(mat,mat);
- }
- }
- int main()
- {
- #ifdef LOCAL
- freopen("test.in","r",stdin);
- #endif
- int f[]={,,,};
- while(scanf("%d%d",&len,&m)!=EOF)
- {
- if(len==)printf("%d\n",);
- else if(len<=)printf("%d\n",f[len-]%m);
- else{
- init();
- pow(len-);
- printf("%d\n",(ans[][]*f[]+ans[][]*f[]+ans[][]*f[]+ans[][]*f[])%m);
- }
- }
- return ;
- }
hdu---(2604)Queuing(矩阵快速幂)的更多相关文章
- HDU.2640 Queuing (矩阵快速幂)
HDU.2640 Queuing (矩阵快速幂) 题意分析 不妨令f为1,m为0,那么题目的意思为,求长度为n的01序列,求其中不含111或者101这样串的个数对M取模的值. 用F(n)表示串长为n的 ...
- HDU 2604 Queuing 矩阵高速幂
Queuing Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- HDU 5667 构造矩阵快速幂
HDU 5667 构造矩阵快速幂 题目描述 解析 我们根据递推公式 设 则可得到Q的指数关系式 求Q构造矩阵 同时有公式 其中φ为欧拉函数,且当p为质数时有 代码 #include <cstdi ...
- HDU 6185 Covering 矩阵快速幂
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6185 题意:用 1 * 2 的小长方形完全覆盖 4 * n的矩形有多少方案. 解法:小范围是一个经典题 ...
- HDU 2157(矩阵快速幂)题解
How many ways?? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 6395 分段矩阵快速幂 HDU 6386 建虚点+dij
http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others) Me ...
- HDU 6470 【矩阵快速幂】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6470 写这道题是为了让自己不要忘记矩阵快速幂如何推出矩阵式子的. 注意 代码是TLE的!! #incl ...
- HDU 5607 graph 矩阵快速幂 + 快速幂
这道题得到了学长的助攻,其实就是一个马尔科夫链,算出一步转移矩阵进行矩阵快速幂就行了,无奈手残 这是我第一回写矩阵快速幂,写的各种毛病,等到调完了已经8点44了,交了一发,返回PE,(发现是少了换行) ...
- HDU 1575(裸矩阵快速幂)
emmmmm..就是矩阵快速幂,直接附代码: #include <cstdio> using namespace std; ; ; struct Matrix { int m[maxn][ ...
- hdu 6395Sequence【矩阵快速幂】【分块】
Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total ...
随机推荐
- 【转载】教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神
原文:教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神 本博文将带领你从入门到精通爬虫框架Scrapy,最终具备爬取任何网页的数据的能力.本文以校花网为例进行爬取,校花网:http:/ ...
- 【转载】UML类图知识整理
原文:UML类图知识整理 UML类图 UML,进阶必备专业技能,看不懂UML就会看不懂那些优秀的资料. 这里简单整理 类之间的关系 泛化关系(generalization) 泛化(generalize ...
- Eclipse中新建WEB项目,JSP页面报错。
在Eclipse中新建java web项目,在JSP页面的第一行提示这个错误: [The superclass "javax.servlet.http.HttpServlet" w ...
- centos 扩展root根分区的大小
目标:将VolGroup-lv_home缩小到125G,并将剩余的空间添加给VolGroup-lv_root 1.首先查看磁盘使用情况[root@localhost ~]# df -h文件系统 ...
- Metasploit RPC服务共享
1) 启动一个新的MSF RPC服务,-P参数后面指定连接到的RPC服务需要提供的口令,-U参数指定连接所需输入的用户名,使用-a 0.0.0.0将RPC服务绑定到所有的网络地址,否则服务默认只绑定到 ...
- poj 1474 Video Surveillance (半平面交)
链接:http://poj.org/problem?id=1474 Video Surveillance Time Limit: 1000MS Memory Limit: 10000K Total ...
- P2P小贷网站业务数据流程分享
P2P小贷网站业务数据流程分享 引言 这是去年年底开发的一个项目,完成后和用户的衔接没有很好的做起来,所以项目就搁浅了.9月以来,看各路P2P风声水起,很是热闹:这里分享下我的设计文档,算是抛砖引玉, ...
- 基于jQuery的移动轮播图(支持触屏)
移动轮播图我看到两款, 一款是无线天猫的m.tmall.com,实现了无缝轮播. 一款是蘑菇街的,没有实现无缝轮播. 我自己重写一个,类似蘑菇街 <!doctype html> <h ...
- D3.js 其他选择元素方法
在上一节中,已经讲解了 select 和 selectAll,以及选择集的概念.本节具体讲解这两个函数的用法. 假设在 body 中有三个段落元素: <p>Apple</p> ...
- Freemarker 浅析 (zhuan)
http://blog.csdn.net/marksinoberg/article/details/52006311 ***************************************** ...