HDOJ 题目5496 Beauty of Sequence(数学)
来源:互联网 发布:玄武智慧数据科技 编辑:程序博客网 时间:2024/05/02 04:41
Beauty of Sequence
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 363 Accepted Submission(s): 161
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 sequenceA 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} .
Now you are given a sequence
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
Input
There are multiple test cases. The first line of input contains an integerT , indicating the number of test cases. For each test case:
The first line contains an integern (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 valuesn for all the test cases does not exceed 2000000 .
The first line contains an integer
The sum of values
Output
For each test case, print the answer modulo 109+7 in a single line.
Sample Input
351 2 3 4 541 2 1 353 3 2 1 2
Sample Output
24054144
Source
BestCoder Round #58 (div.2)
Recommend
hujie | We have carefully selected several similar problems for you: 5498 5497 5496 5495 5494
题目大意:所有子序列的和
150135052015-10-05 00:15:09Accepted54961700MS2816K782 BC++弱渣在努力T^Tac代码
#include<stdio.h>#include<string.h>#include<iostream>#include<map>#define LL __int64#define mod 1000000007using namespace std;LL same[100010];LL qpow(LL a,int b){LL ans=1;while(b){if(b&1)ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}int main(){int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);int i;map<LL,int>mp;LL ans=0;for(i=1;i<=n;i++){LL x;scanf("%I64d",&x);if(mp.count(x)==0){same[i]=0;ans=(ans+qpow(2,n-1)*x%mod)%mod;}else{ans=(ans+(((qpow(2,i-1)-same[mp[x]])*qpow(2,n-i))%mod*x)%mod)%mod;same[i]=same[mp[x]];}same[i]=(same[i]+qpow(2,i-1))%mod;mp[x]=i;}printf("%I64d\n",(ans+mod)%mod);}}
0 0
- HDOJ 题目5496 Beauty of Sequence(数学)
- hdoj 5496 Beauty of Sequence
- hdu 5496 Beauty of Sequence 组合数学
- hdoj 5496 Beauty of Sequence 【求序列所有子序列(去重后)的和】【好题】
- hdu 5496 Beauty of Sequence
- HDU 5496 Beauty of Sequence
- HDU 5496 Beauty of Sequence
- HDOJ 题目4096 BestCoder Sequence(数学,水)
- hdu 5496 Beauty of Sequence 枚举
- hdu 5496 Beauty of Sequence (map维护)
- HDU 5496(Beauty of Sequence-DP)
- hdu 5496 Beauty of Sequence(高效)
- HDU 5496 Beauty of Sequence 线性DP
- hdu5496 Beauty of Sequence
- 数学之美(Beauty Of Mathematics)
- ZOJ 3872 Beauty of Array(数学)
- HDOJ 题目2108Shape of HDU(数学)
- HDOJ 题目1299 Diophantus of Alexandria(数学)
- BestCoder Round #48 ($)HDU5284 wyh2000 and a string problem
- ocp-100
- 使用Mac开发Android/iOS/OS X图标生成工具推荐
- Mybatis系列(九)Spring & Mybatis整合
- C++可变参数模板的小知识
- HDOJ 题目5496 Beauty of Sequence(数学)
- appium初次安装(mac)
- Unity 围住神经猫
- Using OpenCV with Eclipse (plugin CDT)
- Codeforces Round #323 (Div. 1) B. Once Again... (最长不下降序列_DP)
- Kinect2.0+OpenCV获取骨骼图
- Install openCV in Linux
- RAC-DG升级后无法同步应用案例一则
- 菜鸟的Linux历程-LAMP搭建之环境准备