HDOJ 题目5496 Beauty of Sequence(数学)
2015-10-05 00:28
357 查看
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
[align=left]Problem Description[/align]
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}.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, print the answer modulo
109+7
in a single line.
[align=left]Sample Input[/align]
3 5 1 2 3 4 5 4 1 2 1 3 5 3 3 2 1 2
[align=left]Sample Output[/align]
240 54 144
[align=left]Source[/align]
BestCoder Round #58 (div.2)
[align=left]Recommend[/align]
hujie | We have carefully selected several similar problems for you: 5498 5497 5496 5495 5494
题目大意:所有子序列的和
15013505 | 2015-10-05 00:15:09 | Accepted | 5496 | 1700MS | 2816K | 782 B | C++ | 弱渣在努力T^T |
#include<stdio.h> #include<string.h> #include<iostream> #include<map> #define LL __int64 #define mod 1000000007 using 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); } }
相关文章推荐
- iOS UISwitch用法和示例
- hdu 5496 Beauty of Sequence bc#58 组合 离散化
- Android后台进程与UI进程的交互
- Fluent NHibernate关系映射
- POJ 题目1239 ||ZOJ 题目 1499 Increasing Sequences(正反两次DP)
- Android UI ActionBar功能-ActionBarSherlock 的使用
- Android UI ActionBar功能-ActionBarSherlock 的使用
- SynchronousQueue的简单应用
- iOS编程-------UIImageView、手势识别器UIGestureRecognizer
- Android UI ActionBar功能-ActionBarProvider的使用
- Android UI ActionBar功能-ActionBarProvider的使用
- Android UI ActionBar功能-自动隐藏 Action Bar
- Android UI ActionBar功能-自动隐藏 Action Bar
- iOS编程-------事件处理UIEvent / 触摸事件UITouch
- Android UI ActionBar功能-Action Bar 左上角的向上或返回按钮
- iOS图文攻略之UITextfield 键盘回收
- 【解决方法】You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE)
- Android UI ActionBar功能-Action Bar 左上角的向上或返回按钮
- Android UI ActionBar功能-自定义Tab功能
- Android UI ActionBar功能-自定义Tab功能