天天看点

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的累乘啦。

Rainbow Strings
#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
           

继续阅读