zoukankan      html  css  js  c++  java
  • Hdu 5496 Beauty of Sequence (组合数)

    题目链接:

      Hdu 5496 Beauty of Sequence

    题目描述:

      一个整数序列,除去连续的相同数字(保留一个)后,序列的和成为完美序列和。问:一个整数序列的所有子序列的完美序列和?

    解题思路:

      考虑位于i位置数字x的贡献值,假设x是子序列中连续相同数字的第一个,那么x对于i后面的数有2(n-i)个贡献值,对前面的数,要么不选取,要么选取结尾不为x的方案数目。

     1 #include <map>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <iostream>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 typedef long long LL;
     9 const LL maxn = 100010;
    10 const LL mod = 1000000007;
    11 LL a[maxn];
    12 map<LL, LL>M;
    13 
    14 int main ()
    15 {
    16     LL t, n;
    17     scanf ("%lld", &t);
    18 
    19     while (t --)
    20     {
    21         scanf ("%lld", &n);
    22         for (int i=0; i<n; i++)
    23             scanf ("%lld", &a[i]);
    24 
    25         LL sum, cnt, num;
    26         sum = cnt = 0;
    27         M.clear();
    28 
    29         for (int i=0; i<n; i++)
    30         {
    31             num = (cnt + 1 - M[a[i]] + mod) % mod;
    32             sum = (2 * sum % mod + num * a[i] % mod) % mod;
    33             M[a[i]] = (M[a[i]] + cnt + 1) % mod;
    34             cnt = (cnt * 2 + 1) % mod;
    35         }
    36 
    37         printf ("%lld
    ", sum);
    38     }
    39     return 0;
    40 }
    本文为博主原创文章,未经博主允许不得转载。
  • 相关阅读:
    UVA1599 理想路径 Ideal Path(最短路径)
    换根DP
    小w的魔术扑克(树状数组+并查集)
    NOIP 2016蚯蚓(优先队列)
    ZR 动物园
    T105017 seq(DP)
    noip2017酱油记
    noip2017酱油记前篇
    P1985 翻转棋
    luogu P2512 [HAOI2008]糖果传递
  • 原文地址:https://www.cnblogs.com/alihenaixiao/p/4871907.html
Copyright © 2011-2022 走看看