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 ...
随机推荐
- <转>如何改变讨好型人格 | 你根本不需要讨好任何人
在我过去二十多年的生命里一直是一个“讨好者”. 我总是活在别人对我的期待中,我总是不停的追逐着别人对我的认可,我总是像个卑微的奴才一样去满足别人的需求. 但就和大多数的“讨好者”一样,我们越是寻求别人 ...
- 数独Sudoku
数独(すうどく,Sūdoku),是源自18世纪瑞士发明,流传到美国,再由日本发扬光大的一种数学游戏.是一种运用纸.笔进行演算的逻辑游戏.玩家需要根据9×9盘面上的已知数字,推理出所有剩余空格的数字,并 ...
- Common Macros for Build Commands and Properties
https://msdn.microsoft.com/en-us/library/c02as0cs.aspx $(ProjectDir) The directory of the proje ...
- ajax请求、servlet返回json数据
ajax请求.servlet返回json数据 1.方式一 response.setcontenttype("text/html;charset=utf-8"); response. ...
- [JAVA设计模式]第一部分:接口、抽象类、设计原则
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- [资源] Resources on Self-Driving Car
Talk NVIDIA at CES 2016 - Self Driving Cars and Deep Learning GPUs Projects Autoware Open-source sof ...
- Fiddler中session的请求/响应类型与图标对照表
- Android ActionBar以及menu的代码设置样式
menu部分xml代码 <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android= ...
- c++ 临时变量
C++的临时变量 它们是被神所遗弃的孩子,没有人见过它们,更没有人知道它们的名字.它们命中注定徘徊于命运边缘高耸的悬崖和幽深的深渊之间,用自己短暂的生命抚平了生与死之间的缝隙.譬如朝露,却与阳光无缘. ...
- Jsoup:解决java.net.UnknownHostException的问题
Jsoup:解决java.net.UnknownHostException的问题 时间 2013-06-20 11:23:08 CSDN博客 原文 http://blog.csdn.net/xyw ...