首页 > 其他 > 详细

Keep at Most 100 Characters

时间:2020-02-09 09:23:19      阅读:85      评论:0      收藏:0      [点我收藏+]

Given a string which contains only lower case letters, how many different non-empty strings you can get if you can keep AT MOST 100 characters in the original order? (Note: The string obtained is a "sub-sequence" of the original string.)

Input Specification:

Each input file contains one test case, which is only one line containing the string whose length is no larger than 1000.

Output Specification:

Output the number of different non-empty strings if you can only keep at most 100 characters. Since the answer might be super large, you only need to output the answer modulo 1000000007.

Sample Input:

aabac
 

Sample Output:

19
 

Hint:

The strings are:

abcaaabacbabcaabaaaaacabaabcbacaabaaabcabacaaac, and aabac.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define mod 1000000007u
 4 int main()
 5 {
 6 //    freopen("data.txt","r",stdin);
 7     char a[1001];
 8     scanf("%s",a);
 9     int asl=strlen(a)+1;
10     long long op=0;
11     int masl=min(asl,101);
12     vector<long long> v(asl*masl,1);
13     for(int i=1;i<masl;i++)
14     {
15         vector<long long> maxre(26,0);
16         maxre[a[i-1]-a]=1;
17         for(int j=i+1;j<asl;j++)
18         {
19             v[i*asl+j]=(v[i*asl+j-1]+v[(i-1)*asl+j-1]-maxre[a[j-1]-a]+mod)%mod;
20             maxre[a[j-1]-a]=v[(i-1)*asl+j-1];
21         }
22     }
23     for(int i=1;i<masl;i++)
24     op=(op+v[(i+1)*asl-1])%mod;    
25     printf("%lld",op);
26     return 0;
27 }
28  

 

Keep at Most 100 Characters

原文:https://www.cnblogs.com/SkystarX/p/12285761.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!