思路:

构造矩阵,矩阵快速幂!!!

代码如下:

 #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的更多相关文章

  1. ZOJ 3690 &amp; HDU 3658 (矩阵高速幂+公式递推)

    ZOJ 3690 题意: 有n个人和m个数和一个k,如今每一个人能够选择一个数.假设相邻的两个人选择同样的数.那么这个数要大于k 求选择方案数. 思路: 打表推了非常久的公式都没推出来什么可行解,好不 ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. DWR在Spring中应用

    这里以传递一个对象为例,来说明dwr在Spring中是怎么配置的. JSP页面: <script src='dwr/interface/instructionOuterService.js'&g ...

  2. Android之Activity的四种启动模式

    当应用运行起来后就会开启一条线程,线程中会运行一个任务栈,当Activity实例创建后就会放入任务栈中.Activity启动模式的设置在AndroidManifest.xml文件中,通过配置Activ ...

  3. C# socket 实现消息中心向消息平台 转发消息

    公司用到,直接粘代码了 using System; using System.Collections.Generic; using System.Configuration; using System ...

  4. qt QSS文件伪状态

    表 1. 伪状态列表伪状态    描述:checked    button部件被选中:disabled    部件被禁用:enabled    部件被启用:focus    部件获得焦点:hover  ...

  5. 技术揭秘12306改造(一):尖峰日PV值297亿下可每秒出票1032张

    [编者按]12306网站曾被认为是"全球最忙碌的网站",在应对高并发访问处理方面,曾备受网民诟病. 2015年铁路客票春运购票高峰期已过,并且12306网站今年没"瘫痪& ...

  6. web 性能忧化(IIS篇)

    1. 调整IIS 7应用程序池队列长度 由原来的默认1000改为65535. IIS Manager > ApplicationPools > Advanced Settings 2.   ...

  7. Ubuntu14.04搭建LAMP环境

    安装Apache2                                                             sudo apt-get install apache2   ...

  8. quartz2D简单使用

    quartz2D绘图 1:上下文:context,这个翻译不好理解,其实翻译环境更好一点,就是给了你一个画板,你看不到而已 在: CGContextRef ctx = UIGraphicsGetCur ...

  9. android开发 textview根据字数长度自动调整字体大小

    需求:根据输入的值实时显示到textview中预览,但是字体大小是要自动适配的 网上有一个代码,但是在我这里不能用,注意方法:refitText  注释掉的是之前的代码 import com.cars ...

  10. Testing Multi-Tenancy on a Local Machine

    If you are running locally and do not have a domain to map, you can edit your\Windows\System32\drive ...