hdu 3658 How many words
思路:
构造矩阵,矩阵快速幂!!!
代码如下:
#include<cstdio>
#include<vector>
#include<cmath>
#include<iostream>
#include<cstring>
#define ll __int64
#define mod 1000000007
using namespace std;
int let[];
struct ma
{
ll a[][];
}A,B;
ll sum(ma a)
{
ll ans=;
for(int i=;i<;i++)
for(int j=;j<;j++)
ans=(ans+a.a[i][j])%mod;
return ans;
}
void init()
{
int i,j;
for(i='a';i<='z';i++){
let[i-'a']=i;
let[i-'a'+]=i-'a'+'A';
}
for(i=;i<;i++)
for(j=;j<;j++){
if(abs(let[i]-let[j])<=) A.a[i][j]=;
if(abs(let[i]-let[j])<) B.a[i][j]=;
}
}
ma mul(ma a,ma b)
{
ma ans;
for(int i=;i<;i++)
for(int j=;j<;j++){
ans.a[i][j]=;
for(int k=;k<;k++)
ans.a[i][j]=(ans.a[i][j]+a.a[i][k]*b.a[k][j])%mod;
}
return ans;
}
ma pows(ma a,int b)
{
ma ans;
for(int i=;i<;i++)
for(int j=;j<;j++)
ans.a[i][j]=(i==j);
while(b){
if(b&) ans=mul(ans,a);
b>>=;
a=mul(a,a);
}
return ans;
}
int main()
{
init();
int m,t;
scanf("%d",&t);
while(t--){
scanf("%d",&m);
ll res=sum(pows(A,m-))-sum(pows(B,m-));
if(res<) res=(res%mod+mod)%mod;
printf("%I64d\n",res);
}
return ;
}
hdu 3658 How many words的更多相关文章
- ZOJ 3690 & HDU 3658 (矩阵高速幂+公式递推)
ZOJ 3690 题意: 有n个人和m个数和一个k,如今每一个人能够选择一个数.假设相邻的两个人选择同样的数.那么这个数要大于k 求选择方案数. 思路: 打表推了非常久的公式都没推出来什么可行解,好不 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
随机推荐
- Status Bar in iOS7
This is a very important change in iOS 7: the status bar is no longer a separate bar. It’s now somet ...
- MVC4.0 WebApi如何自定义返回数据类型
1.客户端可以通过HTTP Accept消息头来通知服务器客户端想要什么样的MIME类型数据,例如:application/json则代表告诉服务器想要的是Json数据 2.服务器端撇开客户端的请求类 ...
- iis7应用程序池自动关闭问题解决
解决: 应用程序池启动32位应用程序 设置托管管道为集成 (仍然有问题) 图片:123.png 访问网站之前 应用程序池是开启的 访问后 网页报503 service unavailable应用程序池 ...
- P3245: 最快路线
这道题其实还是不难的,只是自己搞混了=-=//晕,做了好久啊,其实就是个spfa,关键是存储路径搞昏了.输出格式要求太严了,航模不能有空格啊,所以因为格式WA了三次,哭啊/(ㄒoㄒ)/~~.贴上代码吧 ...
- Machine Learning 学习笔记 (4) —— 广义线性模型
本系列文章允许转载,转载请保留全文! [请先阅读][说明&总目录]http://www.cnblogs.com/tbcaaa8/p/4415055.html 1. 指数分布族简介 之前的文章分 ...
- 宣讲ppt的技巧
这是一个L运营商的项目,项目规模比较大,中兴的客户群体定位主要是电信运营商,运营商的项目做起来非常累,不是一般的小公司能玩的,一般项目要经过这几个过程,前期信息获得——技术交流引导——实验局测试——投 ...
- Daily Scrum3
今天我们小组开会内容分为以下部分: part 1: 汇报之前分配的任务进度: part 2:分配明天的任务. ◆Part 1 组员进度报告 彭佟小组完成的优化目标: 关于软件防滥用及垃圾信息拦 ...
- UVALive - 6575 Odd and Even Zeroes 数位dp+找规律
题目链接: http://acm.hust.edu.cn/vjudge/problem/48419 Odd and Even Zeroes Time Limit: 3000MS 问题描述 In mat ...
- codeforce 421D D. Bug in Code
题目链接: http://codeforces.com/problemset/problem/421/D D. Bug in Code time limit per test 1 secondmemo ...
- UVA 10078 The Art Gallery
Problem: Century Arts has hundreds of art galleries scattered all around the country and you are hir ...