Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 90 Accepted Submission(s): 26
题解:给出最大相邻后缀的最大前缀让找小写字母组成的串的种数
可以找到规律,当出现数组不等于0的时候,必然是递减的;然后找里面0和连续递减串的个数;
就是26*25^m
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<map> #include<string> using namespace std; const int INF=0x3f3f3f3f; #define SI(x) scanf("%d",&x) #define PI(x) printf("%d",x) #define P_ printf(" ") #define mem(x,y) memset(x,y,sizeof(x)) typedef long long LL; const int MOD=1e9+7; const int MAXN=1e5+100; int a[MAXN]; LL solve(int N){ int cnt=N; a[N]=0; for(int i=2;i<=N;i++){ if(a[i-1]!=0&&a[i]!=a[i-1]-1)return 0; if(a[i-1])cnt--; } LL ans=26; for(int i=1;i<cnt;i++){ ans=ans*25%MOD; } return ans; } int main(){ int T,N; SI(T); while(T--){ SI(N); int cnt; for(int i=1;i<N;i++){ SI(a[i]); } printf("%I64d\n",solve(N)); } return 0; }
原文:http://www.cnblogs.com/handsomecui/p/5246030.html