E - Rainbow Strings

2024-01-26 05:04
文章标签 strings rainbow

本文主要是介绍E - Rainbow Strings,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

如果字符串中的每个字母都不同,则将字符串定义为彩虹字符串。空字符串也被认为是彩虹字符串。
给定一个小写字母字符串,计算彩虹字符串的不同子序列的数量。如果一个子序列中包含索引,但另一个子序列不包含索引,则即使生成的字符串相同,两个子序列也是不同的。
在第一个示例中,有8个子序列。唯一不是彩虹字符串的子序列是 aa 和 aab。
剩下的6个子序列是彩虹串。

输入
输入将由一行和一个仅由小写字母组成的字符串组成。字符串的长度介于1和100000之间(包括1和100000)。

输出
在一行上 写下彩虹序列的数量,取素数11092019的模。

Input1
aab
Output1
6
Input2
icpcprogrammingcontest
Output2
209952

解析:
对于每个字符都有两种情况,选与不选;
所以记录一下每个字符出现的次数 cnt[N];
对于每个字符 i,不选是一种情况,选是 cnt[i]种情况(因为不同的位置是不同的子序列),
所以每个字符 i 就是 cnt[i]+1 种情况。
将这些情况相乘即可。

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define ios ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
int gcd(int a,int b) { return b? gcd(b,a%b) : a; }
typedef pair<int,int> PII;
const double PI=acos(-1.0);
const int N=2e6+10,p=11092019;
int cnt[27];
string s;
void solve()
{cin>>s;for (int i=0;i<s.size();i++) cnt[s[i]-'a']++;int ans=1;for (int i=0;i<26;i++){if (cnt[i]>0) ans=(ans*(cnt[i]+1))%p;}cout<<ans;
}
signed main()
{ios;int T=1;//cin>>T;while (T--) solve(); return 0;
}

这篇关于E - Rainbow Strings的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/645703

相关文章

[LeetCode] 583. Delete Operation for Two Strings

题:https://leetcode.com/problems/delete-operation-for-two-strings/description/ 题目 Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in

Swift 3.0 学习 -- 大写和小写字符串(Uppercase and Lowercase Strings)

在swift2.0的时候,您可以通过字符串的uppercaseString和lowercaseString属性来访问大写/小写版本的字符串。如下:

If an application has more than one locale, then all the strings declared in one language should als

字符串资源多国语言版本的出错问题 假如你仅仅针对国内语言 加上这句即可 //保留中文支持resConfigs "zh"

JavaScript - First step - Strings

var string = 'The revolution will not be televised.';var string = "The revolution will not be televised."; 转义字符 var bigmouth = 'I\'ve got no right to take my place...';bigmouth; 字符串连接 var one =

【Go】strings.Replace 与 bytes.Replace 调优

原文链接:https://blog.thinkeridea.com/201902/go/replcae_you_hua.html 标准库中函数大多数情况下更通用,性能并非最好的,还是不能过于迷信标准库,最近又有了新发现,strings.Replace 这个函数自身的效率已经很好了,但是在特定情况下效率并不是最好的,分享一下我如何优化的吧。 我的服务中有部分代码使用 strings.Replac

hdoj 2371 decoded string. Decode the Strings

http://acm.hdu.edu.cn/showproblem.php?pid=2371 题意:给出编码的原则,给一个字符串,输出该字符串经过m次解码后的字符串。 啊啊啊啊。。。。无耻的看错题意了,以为给出字符串输出经过m次解码的后的字符串,样例死活过不了,赛后才发现问的是“decoded string”. 即解码后的字符串。。 思路:对于 5 3 2 3 1 5 4 helol

C++学习,Strings

C ++支持的字符串的函数: No功能与目的1 strcpy(s1, s2); 将字符串s2复制到字符串s1中。 2 strcat(s1, s2); 将字符串s2连接到字符串s1的末尾。 3 strlen(s1); 返回字符串s1的长度。 4 strcmp(s1, s2); 如果s1和s2相同则返回0; 如果s1 如果s1> s2,则大于0。 5 strchr(s1, ch); 返回指向字符串s

leetcode 893. Groups of Special-Equivalent Strings

原题链接 You are given an array of strings of the same length words. In one move, you can swap any two even indexed characters or any two odd indexed characters of a string words[i]. Two strings words[

Power Strings(KMP算法)

题目描述 Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation

UVA 10679 I love Strings!!!(AC自动机)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1620 ProblemG ILove Strings!!! Input:Standard Input Output:Standard Output TimeLimit: 4 Sec