NEU 1040 Count
1040: Count
时间限制: 1 Sec 内存限制: 128 MB
提交: 59 解决: 23
[提交][状态][讨论版]
题目描述
Many ACM team name may be very funny,such as "Complier_Error","VVVVV".Oh,wait for a minute here.
Is it "W W"+"V",or "W"+"V V V",or something others we can treat as?There are several ways we can treat this name "VVVVV" (5 'V's),as V V can be treat as a W.
For 5 'V's,our have 8 ways.They are:
V V V V V
V W W
W W V
V W V V
W V W
W V V V
V V W V
V V V W
The problem here is that for n 'V's,how many ways do we have to treat it?Because the answer may be too large, you should output the answer module by p.(If n is 0,then we have just one way.)
输入
There are multiple test cases. The first line of the input contains an integer M, meaning the number of the test cases.
For each test cases, there are two integers n and p in a single line.
You can assume that 0<=n<=2100000000, 0<p<=2009.
输出
For each test case, output the answer with case number in a single line.
样例输入
2
5 5
4 7
样例输出
3
5 题目大意:
就是说给你5个V的话“VVVVV”,可能有一部分V连在一起被看做W,问可以看出多少种序列,答案对p取余。
输入:
第一行一个M表示有M个测试数据,
第二行到第M+1行每行两个整数n,p,表示n个V,对p取余。
输出:
一个整数,要求如题。 菲波那切数列??应该吧 好吧,就是斐波那契额,n的数目由n-1和n-2继承来,n比较大,所以矩阵乘法快速幂优化一下递推
#include<cstdio>
#include<cstring>
int p;
struct matrix
{
int a[][];
matrix(matrix &p)
{
for(int i=;i<;i++)
for(int j=;j<;j++)
this->a[i][j]=p.a[i][j];
}
matrix(int x)
{
for(int i=;i<;i++)
for(int j=;j<;j++)
this->a[i][j]=x;
}
matrix()
{
memset(a,,sizeof(a));
for(int j=;j<;j++)
this->a[j][j]=;
}
matrix operator * (matrix &b)
{
matrix c;
for(int i=;i<;i++)
for(int j=;j<;j++)
{
c.a[i][j]=;
for(int k=;k<;k++)
{
c.a[i][j]+=this->a[i][k]*b.a[k][j];
}
c.a[i][j]%=p;
}
return c;
}
};
matrix quickmult(matrix &a,int k)
{
matrix ans,temp(a);
while(k)
{
if(k%)ans=ans*temp;
temp=temp*temp;
k/=;
}
return ans;
}
int main()
{
int m,n;
scanf("%d",&m);
while(m--)
{
scanf("%d%d",&n,&p);
matrix ini,tra;//ini means initial matrix, tra means transform matrix
ini.a[][]=;ini.a[][]=;ini.a[][]=;ini.a[][]=;
tra.a[][]=;tra.a[][]=;tra.a[][]=;tra.a[][]=;
tra=quickmult(tra,n);
ini=ini*tra;
printf("%d\n",ini.a[][]);
}
return ;
}
NEU 1040 Count的更多相关文章
- nodejs api 中文文档
文档首页 英文版文档 本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可. Node.js v0.10.18 手册 & 文档 索引 | 在单一页面中浏览 | JSON格 ...
- <LeetCode OJ> 204. Count Primes
Description: Count the number of prime numbers less than a non-negative number, n. 分析: 思路首先:一个数不是合数就 ...
- 1040 有几个PAT (25 分)
题目链接:1040 有几个PAT (25 分) 做这道题目,遇到了新的困难.解决之后有了新的收获,甚是欣喜! 刚开始我用三个vector数组存储P A T三个字符出现的位置,然后三层for循环,根据字 ...
- 【九度OJ】题目1040:Prime Number 解题报告
[九度OJ]题目1040:Prime Number 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1040 题目描述: Ou ...
- C#中Length和Count的区别(个人观点)
这篇文章将会很短...短到比你的JJ还短,当然开玩笑了.网上有说过Length和count的区别,都是很含糊的,我没有发现有 文章说得比较透彻的,所以,虽然这篇文章很短,我还是希望能留在首页,听听大家 ...
- [PHP源码阅读]count函数
在PHP编程中,在遍历数组的时候经常需要先计算数组的长度作为循环结束的判断条件,而在PHP里面对数组的操作是很频繁的,因此count也算是一个常用函数,下面研究一下count函数的具体实现. 我在gi ...
- EntityFramework.Extended 实现 update count+=1
在使用 EF 的时候,EntityFramework.Extended 的作用:使IQueryable<T>转换为update table set ...,这样使我们在修改实体对象的时候, ...
- 学习笔记 MYSQL报错注入(count()、rand()、group by)
首先看下常见的攻击载荷,如下: select count(*),(floor(rand(0)*2))x from table group by x; 然后对于攻击载荷进行解释, floor(rand( ...
- count(*) 与count (字段名)的区别
count(*) 查出来的是:结果集的总条数 count(字段名) 查出来的是: 结果集中'字段名'不为空的记录的总条数
随机推荐
- jQuery hooks源码学习
段落不够清晰,待整理 看jQuery源码的时候,经常见到含有hooks标志的对象,如cssHooks, attrHooks, propHooks, valHooks. 下面对其中的一段进行解读. jQ ...
- WordPress音乐主题Always1.8
WordPress响应式主题 音乐主题个人博客杂志主题Always主题V1.8 Always主题V1.8是以Ajax加以CSS动画的方式,很好的将优雅的设计感和极度精简的代码同时表现了出来,进而缔造出 ...
- Android Fragment 初步解析
Fragment经常在我们的开发中见到,但是自我感觉对Fragment的理解还是处于初级的阶段,接下来我将用几篇文章尽量深的解析Fragment 让我们开始吧!!! Fragment的生命周期 Fra ...
- ASP.NET CORE读取appsettings.json的配置
如何在appsettings.json配置应用程序设置,微软给出的方法:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/config ...
- yii处理cookie
/** * 设置用户cookie会话 */ public function setCookie() { //set loginName $cookies = Yii::app()->reques ...
- PhotoZoom官方这举动,大写服!
上上周,PhotoZoom Classic7首次特惠活动大家都知道哈~~ 厂商福利限量30套,仅售99RMB,活动一经上线,半天时间一售而光,这说明不是大家不需要这个智能小软件啊,而是,可能,大概,也 ...
- WPF 创建用户控件并引用
项目源码地址:https://github.com/lizhiqiang0204/WpfControlLibrary.git 首先创建新项目->WPF用户控件库项目 在UserControl1. ...
- 【udacity】机器学习-决策树
Evernote Export 1.监督学习 我们向系统中输出样本,并且告诉系统样本标签(target),系统用我们给出的不同样本的成功与失败的信息,构建它对成功或失败的因素的理解. 2.分类与回归之 ...
- navicat Premium远程链接mysql报错
1,报错1057,原来是没有远程权限连接mysql 2.打开my.ini文件,添加skip-grant-tables跳过验证 3.添加到path环境变量,前面是英文下的分号 4.切换到cmd,输入my ...
- Guava 是个风火轮之基础工具 (1)
转自:http://www.jamespan.me/blog/2015/02/08/guava-basic-utilities-1/ Guava 是个风火轮之基础工具 (1) 前言 Guava 是 J ...