hdu 5496 Beauty of Sequence 枚举
来源:互联网 发布:centos系统指令 编辑:程序博客网 时间:2024/05/17 07:48
Beauty of Sequence
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 195 Accepted Submission(s): 79
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 integer T , 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)
枚举第i个数能作为子序列中连续的数字的开头,那么 这个数字对总和的贡献为,下标从0开始
num[i] * 2^(n-i-1) * (2^i - 以和num[i]相等的数字作为结尾的方案数)
然后以num[i]结尾的方案数+= 2^i
#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<map>using namespace std;#define maxn 100007int pow2[maxn];int num[maxn];#define mod 1000000007#define ll long longmap<int,int>haha;int main(){ int t,n; scanf("%d",&t); pow2[0] = 1; for(int i = 1;i < maxn; i++) pow2[i] = pow2[i-1]*2%mod; while(t--){ scanf("%d",&n); for(int i = 0;i < n; i++) scanf("%d",&num[i]); int sum1,ans = 0,sum=0,ha,he; haha.clear(); for(int i = 0;i < n; i++){ ha = haha[num[i]]; he = pow2[i] - ha; if(he < 0) he += mod; sum1 = (ll)he*pow2[n-i-1]%mod*num[i]%mod; ans += sum1; if(ans >= mod) ans -= mod; ha += pow2[i]; if(ha >= mod) ha -= mod; haha[num[i]] = ha; } ans %= mod; if(ans < 0) ans += mod; printf("%d\n",ans); } return 0;}
0 0
- hdu 5496 Beauty of Sequence 枚举
- hdu 5496 Beauty of Sequence
- HDU 5496 Beauty of Sequence
- HDU 5496 Beauty of Sequence
- hdu 5496 Beauty of Sequence (map维护)
- hdu 5496 Beauty of Sequence 组合数学
- HDU 5496(Beauty of Sequence-DP)
- hdu 5496 Beauty of Sequence(高效)
- HDU 5496 Beauty of Sequence 线性DP
- HDU 5496 - Beauty of Sequence (序列 + 统计贡献)
- hdu 5496 Beauty of Sequence bc#58 组合 离散化
- hdoj 5496 Beauty of Sequence
- hdu5496 Beauty of Sequence
- hdu Beauty of Sequence (好题_集合问题)
- HDU5496--Beauty of Sequence(水题)
- HDOJ 题目5496 Beauty of Sequence(数学)
- 哈希+前缀和 hdu5496 Beauty of Sequence
- hdoj 5496 Beauty of Sequence 【求序列所有子序列(去重后)的和】【好题】
- hdu 5495 LCS (bestcoder #58 1002)
- Edison install ROS in two method
- 动态链接库与静态链接库的区别
- QT5 学习之路18---对话框数据传递
- iOS开发之导出ipa文件以及查看内容
- hdu 5496 Beauty of Sequence 枚举
- [about myself] 关于我自己
- 例题 7-7 宝箱 UVa 12325
- VS2010+PCL1.6.0+1.7.2(Win7 64位)安装教程
- 数据挖掘之分类
- JSP
- 白盒测试概述及其方法简介
- 使用脚本获得 消耗Linux操作系统内存的前10个用户
- 条款7中提及工厂method