Beauty of Sequence

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 384    Accepted Submission(s): 168

Problem Description
Sequence is beautiful and the beauty of an integer sequence is defined as follows: removes all but the first element from every consecutive group of equivalent elements of the sequence (i.e. unique function in C++ STL) and the summation of rest integers is the beauty of the sequence.

Now you are given a sequence A of n integers {a1,a2,...,an}. You need find the summation of the beauty of all the sub-sequence of A. As the answer may be very large, print it modulo 109+7.

Note: In mathematics, a sub-sequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example {1,3,2} is a sub-sequence of {1,4,3,5,2,1}.

 
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer n (1≤n≤105), indicating the size of the sequence. The following line contains n integers a1,a2,...,an, denoting the sequence(1≤ai≤109).

The sum of values n for all the test cases does not exceed 2000000.

 
Output
For each test case, print the answer modulo 109+7 in a single line.
 
Sample Input
3
5
1 2 3 4 5
4
1 2 1 3
5
3 3 2 1 2
 
Sample Output
240
54
144
 
Source
 
 
题目大意:定义了beauty,给出一个整数序列, 去除序列中连续相邻的重复元素(只保留一个), 剩下来的数的和称之为序列的beauty.给你一个序列,问你该序列的所有子序列的beauty和对1e9+7的结果。
 
解题思路:
 
我们枚举1---n的每个数字a[i],对于a[i]来说,能产生多少次贡献呢?。i后边的所有组合以及i前边的不是以a[i]为结尾的所有组合的乘积。现在问题转为如何维护不是以a[i]为结尾的所有组合的个数。我们定义事件A:以a[i]为结尾的组合的个数,事件B:不是以a[i]为结尾的组合的个数。 那么 B=2^(i-1)-A。我们现在可以维护A,也就间接维护了B。笔者是用map维护的,其实都无所谓的。如序列:2 1 3 1 1 1。下标从1开始。如i=5时,如果前边有a[i-1]的话,那么就不是i位置产生的贡献,而是i-1位置产生的贡献。但是i-1位置在计算该位置产生贡献的时候已经计算过了,所以不应该重复计算,其他以数字a[i]结尾的位置同理。所以应该找到前边跟a[i]不同的数结尾的组合。
 
#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
const int mod=1e9+7;
const int maxn=1e5+200;
INT a[maxn];
INT pow2[maxn];
map<int,INT>coun;
int main(){
int T,n;
scanf("%d",&T);
pow2[0]=1;
for(int i=1;i<=maxn-100;i++){
pow2[i]=pow2[i-1]*2%mod;
}
while(T--){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%I64d",&a[i]);
}
coun.clear();
coun[0]=1;
INT ans=0;
for(int i=1;i<=n;i++){
INT pre=coun[a[i]];
INT tpre=pow2[i-1]-pre; //i-1
tpre=(tpre%mod+mod)%mod;
INT tmp=a[i]*tpre%mod*pow2[n-i]%mod;
ans=(ans+tmp)%mod;
pre=pow2[i-1]+pre;
coun[a[i]]=pre;
}
printf("%I64d\n",ans);
}
return 0;
}

  

 
 
 
 

HDU 5496——Beauty of Sequence——————【考虑局部】的更多相关文章

  1. Hdu 5496 Beauty of Sequence (组合数)

    题目链接: Hdu 5496 Beauty of Sequence 题目描述: 一个整数序列,除去连续的相同数字(保留一个)后,序列的和成为完美序列和.问:一个整数序列的所有子序列的完美序列和? 解题 ...

  2. HDU 5496 Beauty of Sequence

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5496 Beauty of Sequence Problem Description Sequence ...

  3. HDU 5783 Divide the Sequence(数列划分)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  4. hdu-5496 Beauty of Sequence(递推)

    题目链接: Beauty of Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java ...

  5. 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence

    // 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...

  6. hdu 4893 Wow! Such Sequence!(线段树)

    题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...

  7. Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)

    Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...

  8. HDU 5063 Operation the Sequence(暴力)

    HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...

  9. HDU 5288 OO’s Sequence [数学]

     HDU 5288 OO’s Sequence http://acm.hdu.edu.cn/showproblem.php?pid=5288 OO has got a array A of size ...

随机推荐

  1. Python模块-sys模块

    sys.version        获取Python解释程序的版本信息 >>> sys.version '2.7.12 (default, Dec 4 2017, 14:50:18 ...

  2. stm32之内部功能

    本文将提到以下内容: 位带操作 中断 printf重定向 随机数发生器RNG AD/DA DMA 高性能计算能力 加密 ART加速 一.位带操作 在学习51单片机的时候就使用过位操作,通过关键字sbi ...

  3. CentOS 7 rsync+inotify实现实时同步

    测试环境如下: inotify-slave IP : 172.16.0.222 inotify-master IP : 172.16.0.233 对两台机的要求: 安装依赖包gcc: yum inst ...

  4. 【MySQL】MySQL悲观锁 + 事物 + for update 解决普通流量并发的问题

    使用mysql悲观锁解决并发问题   最近学习了一下数据库的悲观锁和乐观锁,根据自己的理解和网上参考资料总结如下: 悲观锁介绍(百科): 悲观锁,正如其名,它指的是对数据被外界(包括本系统当前的其他事 ...

  5. 嵌入式linux环境搭建

    花了两天时间,终于搭建好了板子上的linux驱动开发环境,不容易呀,做个笔记. 首先搭建PC上的编译环境,因为编译的驱动是在板子上运行的,第一步当然需要安装交叉编译器,即arm-none-linux- ...

  6. 微观SOA:服务设计原则及其实践方式

    大 量互联网公司都在拥抱SOA和服务化,但业界对SOA的很多讨论都比较偏向高大上.本文试图从稍微不同的角度,以相对接地气的方式来讨论SOA, 集中讨论SOA在微观实践层面中的缘起.本质和具体操作方式, ...

  7. CSS学习系列2 -- CSS中的清除浮动

    CSS中有一个很常见的问题,就是元素的浮动. 那么,到底什么是元素的浮动呢,我们来看一个例子 举个例子,在一个div里面内部有浮动元素的话,这个浮动元素会让这个div的高度塌陷. .myDiv{ ba ...

  8. vivado中使用debug不能连接到vcse_server

    打开 Xilinx Design Tools -> ISE Design Suite 14.7 -> Accessories -> ISE Design Suite 64 Bit C ...

  9. raspberry是个什么玩意

    今天Wilson同学取回一个书本大小的包裹,说买回来一台小电脑,只有信用卡大小! 这是第一次听说和看见raspberry Pi. 一块开发板上有四个USB.一个视频接口.一个音频接口.一个网线接口和电 ...

  10. 【linux安装软件步骤】

    一.解析linux应用软件安装包: 通常Linux应用软件的安装包有三种: tar包,如software-1.2.3-1.tar.gz.它是使用UNIX系统的打包工具tar打包的. rpm包,如sof ...