hdoj 5496 Beauty of Sequence 【求序列所有子序列(去重后)的和】【好题】
来源:互联网 发布:上班记录软件 编辑:程序博客网 时间:2024/05/22 17:36
Beauty of Sequence
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 304 Accepted Submission(s): 135
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
序列去重 后的和 —— 如 1 2 2 2 3 ,去重 后和为1 + 2 + 3 = 6。
题意:给你一个N个数组成的序列,求出所有子序列(去重后)的和。
思路:考虑每个元素作为第一个元素的贡献,然后计数即可。
AC代码:
#pragma comment(linker, "/STACK:1024000000,1024000000")#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <string>#include <cstring>#include <map>#include <vector>#include <queue>#include <stack>#include <set>#include <cstdlib>#define ll o<<1#define rr o<<1|1#define CLR(a, b) memset(a, (b), sizeof(a))using namespace std;typedef long long LL;const int MAXN = 1e5 + 10;typedef pair<int, int> pii;const int INF = 1e9 + 10;const double PI = acos(-1.0);const double eps = 1e-6;const int MOD = 1e9 + 7;void add(LL &x, LL y) { x += y; x %= MOD; }using namespace std;int a[MAXN];LL f[MAXN];;map<int, LL> res;int main(){ f[0] = 1; for(int i = 1; i <= MAXN - 1; i++) { f[i] = f[i - 1] * 2 % MOD; } int t; scanf("%d", &t); while(t--) { int n; scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); } LL ans = 0; LL sum = 0; res.clear(); for(int i = 1; i <= n; i++) { add(sum, f[i - 1]); add(res[a[i]], f[i - 1]); add(ans, f[n - i] * a[i] % MOD * ((sum - res[a[i]] + MOD) % MOD + 1) % MOD); } printf("%lld\n", ans); } return 0;}
0 0
- hdoj 5496 Beauty of Sequence 【求序列所有子序列(去重后)的和】【好题】
- hdoj 5496 Beauty of Sequence
- HDU 5496 - Beauty of Sequence (序列 + 统计贡献)
- HDOJ 题目5496 Beauty of Sequence(数学)
- hdu Beauty of Sequence (好题_集合问题)
- 【DP】最大子序列的和 (sequence)
- 求最小子序列和 求最小的正序列 求最大子序列乘积
- ZOJ 3872 Beauty of Array 动态规划子序列
- HDOJ 1003 MaxSum(动态规划 求最大子序列和)
- 求子序列的和的最大值
- codeforce_894C_给你原序列所有连续子序列的GCD从小到大,求原序列_构造
- 求序列的最大子序列和的问题
- 求最大子序列的和
- 求连续子序列的最大和
- 求数组的最大子序列和
- 求最大子序列的和
- 求数组最大子序列的和
- 求最大连续子序列的和
- 【AMPPZ2014】【BZOJ4143】The Lawyer
- hdu 4018 Parsing URL
- hadoop学习笔记之分布式计算框架
- [PAT]1097. Deduplication on a Linked List (25)
- 50Pow(x, n)
- hdoj 5496 Beauty of Sequence 【求序列所有子序列(去重后)的和】【好题】
- Linux 学习笔记 常用命令
- hdu5119 Happy Matt Friends( DP )
- 国庆随笔
- 插头dp模板(简单路径+一条回路+广义路径)
- ACM学习-动态规划-基因查找序列问题
- 软件工程之软件测试
- iOS - 常用的iOS Mac框架和库以及常用的中文开发博客
- Java中接口的清晰+形象理解