Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything.
At last, after some thought, he thought of something. Let's say there is a word s, consisting of |s| lowercase Latin letters. Then for one operation you can choose a certain position p (1 ≤ p < |s|) and perform one of the following actions:
- either replace letter sp with the one that alphabetically follows it and replace letter sp + 1 with the one that alphabetically precedes it;
- or replace letter sp with the one that alphabetically precedes it and replace letter sp + 1 with the one that alphabetically follows it.
Let us note that letter "z" doesn't have a defined following letter and letter "a" doesn't have a defined preceding letter. That's why the corresponding changes are not acceptable. If the operation requires performing at least one unacceptable change, then such operation cannot be performed.
Two words coincide in their meaning iff one of them can be transformed into the other one as a result of zero or more operations.
Sherlock Holmes needs to learn to quickly determine the following for each word: how many words can exist that coincide in their meaning with the given word, but differs from the given word in at least one character? Count this number for him modulo 1000000007 (109 + 7).
Input
The input data contains several tests. The first line contains the only integer t (1 ≤ t ≤ 104) — the number of tests.
Next t lines contain the words, one per line. Each word consists of lowercase Latin letters and has length from 1 to 100, inclusive. Lengths of words can differ.
Output
For each word you should print the number of different other words that coincide with it in their meaning — not from the words listed in the input data, but from all possible words. As the sought number can be very large, print its value modulo 1000000007 (109 + 7).
Examples
1
ab
1
1
aaaaaaaaaaa
0
2
ya
klmbfxzb
24
320092793
题意:给定长度小于100的字符串,每次操作可以把相邻的字符对,一个+1,一个-1,但要保证所有字符在'a'到'z'范围里。求原字符串可以转化为多少种字符串。
思路:注意到相邻的一个+1,一个-1,之和是不变的,而且不难证明长度相同,之和相同的时候可以相互转化。所以对于对应长度、对应和,其种类是一定的,我们直接预处理出有多少种。dp[Len][sum]表示长度为Len的时候之和为sum的种类数。 避免讨论,我们把a-z对应为1-26,而不是0-25。
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) #define ll long long using namespace std; const int maxn=110; const int Mod=1e9+7; int dp[maxn][maxn*26],sum[maxn]; char c[maxn]; void solve() { dp[0][0]=1; rep(i,1,100){ rep(j,i,i*26){ rep(p,1,26){ if(j-p>=0) (dp[i][j]+=dp[i-1][j-p])%=Mod; } } } } int main() { int T,N; solve(); scanf("%d",&T); while(T--){ scanf("%s",c+1); N=strlen(c+1); rep(i,1,N) sum[i]=sum[i-1]+c[i]-'a'+1; printf("%d ",(dp[N][sum[N]]+Mod-1)%Mod); } return 0; }