hdu3658 How many words
来源:互联网 发布:hibernate数据库并发 编辑:程序博客网 时间:2024/05/16 10:00
How many words
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 259 Accepted Submission(s): 128
Problem Description
In order to make a new word, we will pick out m letters from all the upper case letters and lower case letters(from `a' to `Z'). Therefore, that means you can pick some same letters. But here are two rules:
● as to all the neighbour letters, the absolute value of their ASCII code must be not greater than 32.
● there must be at least one pair of neighbour letters whose absolute value of ASCII code is exactly equal to 32. For example, considering the word in the form like "Xx" or "xX", the neighbour letters have an absolute value of ASCII code exactly equal to 32.
Now how many di erent words can we get?
● as to all the neighbour letters, the absolute value of their ASCII code must be not greater than 32.
● there must be at least one pair of neighbour letters whose absolute value of ASCII code is exactly equal to 32. For example, considering the word in the form like "Xx" or "xX", the neighbour letters have an absolute value of ASCII code exactly equal to 32.
Now how many di erent words can we get?
Input
The first line of input is the number of test case. For each test case, there is only one line contains one integer m(2 ≤ m ≤ 109).
Output
For each test case output one line, just the answer mod 1000000007.
Sample Input
4231007926778
Sample Output
524056533550434773908369
Author
windy7926778
Source
2010 Asia Regional Chengdu Site —— Online Contest
Recommend
lcy
简单的矩阵快速幂。
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define MOD 1000000007typedef struct{ long long a[55][55];}Matrix;Matrix Mul(Matrix x,Matrix y){ int i,j,k; Matrix tag; for (i=0;i<52;i++) { for (j=0;j<52;j++) { tag.a[i][j]=0; for (k=0;k<52;k++) { tag.a[i][j]+=x.a[i][k]*y.a[k][j]; tag.a[i][j]%=MOD; } } } return tag;}Matrix a,b;int main(){ int i,j,n,T,p; long long ans; scanf("%d",&T); while(T--) { scanf("%d",&n); for (i=0;i<52;i++) { for (j=0;j<52;j++) { a.a[i][j]=(abs(i-j)<=26); b.a[i][j]=0; } b.a[i][0]=1; } p=n; n--; while(n) { if (n&1) b=Mul(a,b); a=Mul(a,a); n>>=1; } ans=0; for (i=0;i<52;i++) { ans+=b.a[i][0]; ans%=MOD; } for (i=0;i<52;i++) { for (j=0;j<52;j++) { a.a[i][j]=(abs(i-j)<26); b.a[i][j]=0; } b.a[i][0]=1; } n=p; n--; while(n) { if (n&1) b=Mul(a,b); a=Mul(a,a); n>>=1; } for (i=0;i<52;i++) { ans+=MOD-b.a[i][0]; ans%=MOD; } printf("%I64d\n",ans); } return 0;}
- hdu3658 How many words
- HDU3658 How many words 矩阵快速幂
- hdu3658 How many words 矩阵快速幂 + dp
- hdu3658 How many words 矩阵递推分析
- HDU 3658 How many words
- hdu 3658 How many words
- 杭电acm 3658How many words
- hdu 3658 How many words dp+矩阵连乘
- HDU - 3658 How many words 矩阵快速幂
- HDU 3658 How many words (矩阵快速幂&递推)
- How many
- hdu 3658 HDU 3658 How many words(矩阵快速幂)
- Problem 17 - How many letters would be needed to write all the numbers in words from 1 to 1000?
- How many zeros and how many digits?
- How many zeros and how many digits?
- One meaning match many words
- how many java objects?
- How many的用法
- 线程--BlockingQueue
- SpringMVC请求处理流程(附图)
- NSXMLParser具体解析xml的应用详解
- inner join 和 outer join 的区别
- Linux 编程
- hdu3658 How many words
- 撕破虚伪面具:VC 不投资的5个信号
- Debugging the kernel using Ftrace
- android sdk, adt等的下载
- swf文件结构
- LINUX内核之中断(4)--时间管理
- vs不支持通过afxgetmainwnd()获取窗口句柄
- Windows内核函数的命名
- JMS ActiveMQ学习(一)