hdu5496 Beauty of Sequence
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 383 Accepted Submission(s): 167
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}.
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.
a single line.
5
1 2 3 4 5
4
1 2 1 3
5
3 3 2 1 2
54
144
这题看了好长时间题解,终于理解了。因为子序列太多,所以可以考虑每一个元素贡献的价值,对于每个数, 我们只算它出现在连续相同元素的第一个时的贡献, 这样会使计算简便很多. 假设当前的数是a[i], 那么i后面的数可以随便选有2^(n-i)种. 考虑a[i]前面的数, 要么一个不选, 要么选择的最后一个数和a[i]不同, 那么我们只要把前面出现过的i的位置记录下来,分别为b,c,d,..那么总的个数为2^(i-1)-2^(b-1)-2^(c-1)-...这样就可以算出来了。
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define inf 0x7fffffff
#define maxn 100070
#define MOD 1000000007
map<int,int>mp;
map<int,int>::iterator it;
ll a[maxn],cishu[maxn];
ll kuaisumi(ll a,ll b,int c)
{
ll ans = 1;
a=a%c;
while(b>0)
{
if(b%2==1)
ans=(ans*a)%c;
b=b/2;
a=(a*a)%c;
}
return ans;
}
ll mul(ll x){
return kuaisumi(2,x,MOD);
}
int main()
{
ll m,i,j,T;
ll n;
scanf("%lld",&T);
while(T--)
{
scanf("%lld",&n);
for(i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
memset(cishu,0,sizeof(cishu));
mp.clear();
ll ans=0;
for(i=1;i<=n;i++){
if(!mp.count(a[i])){
ans=(ans+a[i]*mul(n-1))%MOD;
}
else{
ans=(ans+ a[i]*( mul(i-1)-mp[a[i] ])%MOD*mul(n-i)%MOD )%MOD;
}
mp[a[i] ]=(mp[a[i] ]+mul(i-1) )%MOD;
}
printf("%lld\n",(ans+MOD)%MOD);
}
return 0;
}
hdu5496 Beauty of Sequence的更多相关文章
- hdu-5496 Beauty of Sequence(递推)
题目链接: Beauty of Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java ...
- HDU 5496 Beauty of Sequence
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5496 Beauty of Sequence Problem Description Sequence ...
- HDU 5496——Beauty of Sequence——————【考虑局部】
Beauty of Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- Hdu 5496 Beauty of Sequence (组合数)
题目链接: Hdu 5496 Beauty of Sequence 题目描述: 一个整数序列,除去连续的相同数字(保留一个)后,序列的和成为完美序列和.问:一个整数序列的所有子序列的完美序列和? 解题 ...
- HDU 5496 - BestCoder Round #58 - Beauty of Sequence
题目链接 : http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=637&pid=1002 思路 : 考 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- HDU6592 Beauty Of Unimodal Sequence
Beauty Of Unimodal Sequence 给一个序列,在满足单调递增或者单调递减或者先增后减的最长子序列集合里找到下标字典序最大以及最小的两个子序列,输出这两个子序列里元素的下标. n≤ ...
- 2019年杭电多校第二场 1002题Beauty Of Unimodal Sequence(LIS+单调栈)
题目链接 传送门 思路 首先我们对\(a\)正反各跑一边\(LIS\),记录每个位置在前一半的\(LIS\)中应该放的位置\(ans1[i]\),后一半的位置\(ans2[i]\). 对于字典序最小的 ...
- codeforces 336C Vasily the Bear and Sequence(贪心)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Vasily the Bear and Sequence Vasily the b ...
随机推荐
- 剑指offer 面试题10.1:青蛙跳台阶
题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果). 编程思想 对于本题,前提只有 一次 1阶或者2阶的跳法.a.如果两种跳 ...
- Burp suite的系列介绍 (1)
前言 为了进行Web安全方面的学习,Burp suite是必备的工具之一,我们将会从多个模块进行逐步的学习. Burp suite的应用场景 1.HTTP服务端接口测试. 2.HTTP客户端和HTTP ...
- 【TNS】TNS-00515 TNS-12560 TNS-12545解决方案
今天同事的plsql连接不上数据库,我用他的本地tnsping是不通的,于是上服务器上查看下,结果发现监听没起来,不知道怎么就断了 再次尝试重启 lsnrctl start 发现直接报错: NSLSN ...
- Electron小白入门自学笔记(一)
码文不易啊,转载请带上本文链接呀,感谢感谢 https://www.cnblogs.com/echoyya/p/14297176.html 一.从Hello Electron开始 创建一个空的文件夹, ...
- 开发中经常使用到的Xcode快捷键
工欲善其事必先利其器. 有了这些快捷键加持,你写代码不仅很6而且还很好看. 这些快捷键都是平时使用频率非常高的,今天整理出来分享给大家了. 左缩进:Cmd + [ 右缩进:Cmd + ] 代码格式化/ ...
- 面试官问我CAS,我一点都不慌
文章以纯面试的角度去讲解,所以有很多的细节是未铺垫的. 文章中写到的处理线程安全的思路每一项技术都可以写出一篇文章,AQS.Synchronized.Atomic...周末肝起来!下周再来给大家安排! ...
- CentOS 7.2系统安装步骤
CentOS 7.2系统安装步骤 1.把系统U盘插到服务器上,然后启动服务器进入BIOS界面选择U盘启动. 根据服务器的不同,进入BIOS界面的按钮也不一样,主流的有F10.F11.F12.F2.ES ...
- 正向代理 forward proxy、反向代理 reverse proxy、透明代理 transparent proxy
https://zh.wikipedia.org/wiki/反向代理 反向代理在计算机网络中是代理服务器的一种.服务器根据客户端的请求,从其关系的一组或多组后端服务器(如Web服务器)上获取资源,然后 ...
- TCP报文段的首部格式 20字节的固定首部
<---- IP首部 TCP首部 TCP报文段的数据部分 <---- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...
- OSS与文件系统的对比 文件存储 块存储 对象存储
基本概念介绍_开发指南_对象存储 OSS-阿里云 https://help.aliyun.com/document_detail/31827.html 强一致性 Object 操作在 OSS 上具有 ...