前言
思路
状态表示 :
f
[
i
]
[
j
]
f[i][j ]
f[i][j]前
i
i
i个字母里面,和为
j
j
j的方案数
状态计算 :
f
[
i
]
[
j
]
+
=
f
[
i
−
1
]
[
j
−
k
]
f[i][j] += f[i-1][j-k]
f[i][j]+=f[i−1][j−k]
初始化 :
f
[
1
]
[
0
−
26
]
=
1
,
f
[
i
]
[
0
]
=
1
f[1][0-26] = 1 ,f[i][0]=1
f[1][0−26]=1,f[i][0]=1
然后我们预处理出来所有的方案数即可,最后直接输出
CODE
// Problem: P1385 密令
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1385
// Memory Limit: 125 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//��һ�δ��Ϻ�վ֮�� ��Ϊʹ��#define int long long TLE���¿��˺ܾõ�ʱ�� ���˼���ģ��
//����ʹ�ø��ӵ�ģ��
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
#define IOS ios::sync_with_stdio(false);
#define CIT cin.tie(0);
#define COT cout.tie(0);
#define ll long long
#define x first
#define y second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),x.end()
typedef priority_queue<int,vector<int>,greater<int>> Pri_m;
typedef pair<int,int> pii;
typedef vector<int> VI;
map<int,int> mp;
const int N = 110,M = 2700 , MOD = 1e9+7;
ll f[N][M];
void init(){
//初始化
for(int i=0;i<26;i++){
f[1][i] = 1;
}
for(int i=2;i<=100;i++){
f[i][0] = 1;
for(int j = 1;j<=M;j++){
for(int k =0;k<26;k++){
if(j - k>=0 )
f[i][j] = (f[i][j] + f[i-1][j-k])%MOD;
}
}
}
}
void solve()
{
string s;cin>>s;
ll sum = 0 ;
for(int i=0;i<s.size();i++){
sum+= (s[i] - 'a');
}
cout<<f[s.size()][sum]%MOD -1<<endl;
}
/**mYHeart is my algorithm**/
int main()
{
init();
int t;cin>>t;while(t -- )
solve();
return 0;
}