zoukankan      html  css  js  c++  java
  • Colorful Subsequence

    题目描述

    You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 109+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings.

    Here, a subsequence of a string is a concatenation of one or more characters from the string without changing the order.

    Constraints
    ·1≤N≤100000
    ·S consists of lowercase English letters.
    ·|S|=N

    输入

    Input is given from Standard Input in the following format:

    N
    S

    输出

    Print the number of the subsequences such that all characters are different, modulo 109+7.

    样例输入

    4
    abcd

    样例输出

    15

    提示

    Since all characters in S itself are different, all its subsequences satisfy the condition.

     代码:

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const ll p=1e9+7;
    ll n,a[100],ans=1;
    string s;
    int main() {
      cin >> n >> s;
      for (int i = 0; i < n; i++) {
        a[s[i] - 'a']++;
      }
      for (int i = 0; i < 26; i++) {
        ans = ans * (a[i] + 1) % p;
      }
      printf("%lld
    ", ans-1);
    }
  • 相关阅读:
    解决span中的内容不换行
    javascript中apply、call和bind的区别
    vuex及其属性应用
    55.动态加载Html
    58.圆角图片
    57.动态添加子View(Java/XML两种方式)
    56.Java与js交互
    59.仿微信的图片浏览器
    64.判断当前线程是否是主线程
    61.自定义Indicator
  • 原文地址:https://www.cnblogs.com/Accpted/p/11188668.html
Copyright © 2011-2022 走看看