用dp[c]表示以c开头,形成的后面包含所有的字符串的最大长度。res[c]表示以c开头字符串长度为当前最大长度加1形成的字符串的个数。。
#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 100005
#define maxm 200005
#define eps 1e-7
#define mod 1000000007
#define INF 0x3f3f3f3f
#define PI (acos(-1.0))
#define lowbit(x) (x&(-x))
#define mp make_pair
#define ls o<<1
#define rs o<<1 | 1
#define lson o<<1, L, mid
#define rson o<<1 | 1, mid+1, R
#define pii pair<int, int>
#pragma comment(linker, "/STACK:16777216")
typedef long long LL;
typedef unsigned long long ULL;
//typedef int LL;
using namespace std;
LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}
LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}
// head
char s[maxn];
int dp[27];
LL res[27];
LL xp[maxn];
int n;
void work()
{
scanf("%s", s+1);
n = strlen(s+1);
memset(dp, 0, sizeof dp);
memset(res, 0, sizeof res);
for(int i = n; i >= 1; i--) {
char c = s[i] - 'a';
int mi = INF;
LL t = 0;
for(int j = 0; j < 26; j++) mi = min(dp[j], mi);
for(int j = 0; j < 26; j++) {
if(dp[j] == mi) t += res[j];
else t += xp[mi];
t %= mod;
}
dp[c] = mi + 1;
res[c] = t;
}
int mi = INF;
LL ans = 0;
for(int i = 0; i < 26; i++) mi = min(mi, dp[i]);
for(int i = 0; i < 26; i++) {
if(mi == dp[i]) ans += res[i];
else ans += xp[mi];
ans %= mod;
}
ans = ((xp[++mi] - ans) + mod) % mod;
printf("%d %lld\n", mi, ans);
}
int main()
{
xp[0] = 1;
for(int i = 1; i <= 100000; i++) xp[i] = xp[i-1] * 26 % mod;
int _;
scanf("%d", &_);
for(int i = 1; i <= _; i++) {
printf("Case #%d:\n", i);
work();
}
return 0;
}