Rainbow Strings

Problem E    

 Rainbow Strings

Time limit: 1 second

Defifine 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 are

identical.

In the fifirst example, there are 8 subsequences. The only subsequences that aren’t rainbow strings are aa and aab.

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 string

is between 1 and 100 000 (inclusive).

Output

Write on a single line the number of rainbow sequences, modulo the prime 11 092 019.

PacNW 2019—Division 1 Problem E: Rainbow Strings

11Examples

Sample Input 1 Sample Output 1

aab

6

Sample Input 2 Sample Output 2

icpcprogrammingcontest

209952     

題目大意(反正當時我也沒咋看懂><)

定義一個沒有包含重複字符的字符串爲彩虹字符串,現給出一個長度不超過100000的字符串,求出其可以作爲彩虹字符串的子序列數,對答案取模209952。

思路:把所有的n個字符中每個字符出現的次數求出來,答案就是n個數中取m個數相乘的和(0<m<=n),因爲彩虹串與字符的順序無關,而且求的是子串嘛。

顯然答案不好求。思考一下,其實這其實和求一個整數的正因子個數類似,就把每個字符出現的個數當做正因子就可以了,對於本題而言要求正因子個數的那個整數,就是上面n個數的乘積。

對於一個數的正因子個數,根據算數基本定理,就是ans=(1+a1)*(1+a2)*...*(1+an)     (ai是正因子)。

那麼,如果每個字符出現的是f(i)的話,那麼答案就是(f(i)+1)從1到n的累乘啦。

#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
	string s;
	cin>>s;
	map<char,ll> mp;
	for(ll i=0;i<s.length();i++) mp[s[i]]++;
	ll ans=1;
	for(auto m:mp) ans=(ans*(m.second+1))%11092019;
	cout<<ans<<endl;
	
	return 0;
}
//寫的時候要把類型全都變成ll,不然會爆int

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章