https://nanti.jisuanke.com/t/45349
1000ms
262144K
Define a string to be a rainbow string if every letter in the string is distinct. An empty string is also considered a rainbow string.Given a string of lowercase letters, compute the number of different subsequences which are rainbow strings. Two subsequences are different if an index is included in one subsequence but not the other, even if the resulting strings areidentical.
In the first example, there are 8 subsequences. The only subsequences that aren't rainbow strings are aaaa and aabaab.The remaining 6 subsequences are rainbow strings.
input
The input will consist of a single line with a single string consisting solely of lowercase letters. The length of the stringis between 1 and 100 000 (inclusive).
output
Write on a single line the number of rainbow sequences, modulo the prime 11092019.
样例输入1复制
aab
样例输出1复制
6
样例输入2复制
icpcprogrammingcontest
样例输出2复制
209952
题意:所有由不同字符组成的子串有多少个。
思路:就是求当前字符串中所有字符有多少种排列组合,转化为知道所有质因子,利用算术基本定理,求因数的个数。
#include<iostream>
#include<cstring>
#include<map>
#define ll long long
using namespace std;
const int mod = 11092019;
map<char,int> mp;
int main()
{
string s;
cin>>s;
for(int i=0; i<s.size(); i++)
{
mp[s[i]]++;
}
ll ans = 1;
for(auto a : mp)
{
ans = (ans *(1 + a.second)) % mod;
}
cout<<ans;
return 0;
}