hdu-5496 Beauty of Sequence(递推)
题目链接:
Beauty of Sequence
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 813 Accepted Submission(s): 379
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}.
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.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e5+10;
const LL mod=1e9+7;
LL dp[maxn],num,sum[maxn];
map<int,LL>mp;
int n,a[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
mp.clear();
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
sum[1]=a[1];num=1;mp[a[1]]=1;
for(int i=2;i<=n;i++)
{
dp[i]=(a[i]+sum[i-1])%mod;
dp[i]=(dp[i]+(num-mp[a[i]]+mod)%mod*a[i])%mod;
mp[a[i]]=(mp[a[i]]+num+1)%mod;
num=(num*2+1)%mod;
sum[i]=(sum[i-1]+dp[i])%mod;
}
printf("%lld\n",sum[n]);
}
return 0;
}
hdu-5496 Beauty of Sequence(递推)的更多相关文章
- Hdu 5496 Beauty of Sequence (组合数)
题目链接: Hdu 5496 Beauty of Sequence 题目描述: 一个整数序列,除去连续的相同数字(保留一个)后,序列的和成为完美序列和.问:一个整数序列的所有子序列的完美序列和? 解题 ...
- 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 5860 Death Sequence(递推)
HDU 5860 Death Sequence(递推) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 Description You ...
- HDU 5950 Recursive sequence 递推转矩阵
Recursive sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- hdu 5860 Death Sequence(递推+脑洞)
Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historian liv ...
- hdu 5950 Recursive sequence 递推式 矩阵快速幂
题目链接 题意 给定\(c_0,c_1,求c_n(c_0,c_1,n\lt 2^{31})\),递推公式为 \[c_i=c_{i-1}+2c_{i-2}+i^4\] 思路 参考 将递推式改写\[\be ...
- 题解报告:hdu 2084 数塔(递推dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这 ...
- HDU 5965 三维dp 或 递推
题意:= =中文题 思路一:比赛时队友想的...然后我赛后想了一下想了个2维dp,但是在转移的时候,貌似出了点小问题...吧?然后就按照队友的思路又写了一遍. 定义dp[i][j][k],表示第i列, ...
随机推荐
- [moka同学笔记]yii2.0缓存
1.控制器中CacheDemoController.php <?php /** * Created by PhpStorm. * User: moka同学 * Date: 2016/06/29 ...
- wap网站safari浏览器和微信cooke不能登录问题
wap网站safari浏览器cooke不能登录问题: http://wenku.baidu.com/link?url=VnPxl43PySYVygt09vkQ7xwxOD0JCXNtw3Fx7100j ...
- osx的终端软件iterm2 之 修改外观 和 常用快捷键小结
1.修改外观:透明,自己配色,最好还有个透明的小背景,比如这样: 那么你就要这样修改: 2.快捷键小结 (1)⌘ + d 横着分屏 / ⌘ + shift + d 竖着分屏 : 适合多操作的时候 ( ...
- 调用存储过程从EntityFramework
Prerequisites The prerequisite for running these examples are the following sample tables with test ...
- sass开发过程中遇到的几个坑
1.安装sass被墙的问题 安装完`ruby`后,打开`ruby cmd` 输入`gem install sass`,安装失败,有可能是镜像源的问题,也有可能是墙的问题. 因为公司内网的奇葩限制,各种 ...
- Azure SQL Database 时间点还原(Point in Time Restore)功能
微软中国TechNet 7 Oct 2014 9:17 PM Comments 0 Likes 原文地址:http://blogs.technet.com/b/azuretw/archive/20 ...
- Opengles 管线编程介绍
OpenGL ES 2.0可编程管道 上图橙色部分(Vertex Shader和Fragment Shader)为此管道的可编程部分.整个管道包含以下两个规范: 1) OpenGL ...
- 转 asp.net中如何退出整个框架(frameset),回到登录界面
如: <frameset rows= "74,*,0,0 " cols= "* " frameborder= "NO " border ...
- Installation failed with message INSTALL_FAILED_UID_CHANGED.--APK安装失败解决方法
出现此错误原因大都为:手机上原来APK存在残留,即没有卸载干净,导致不能安装新的APK 解决办法: 1.手机上手动卸载出现问题的APP,再重新安装 2.如果apk无法卸载,则将apk相关文件和相关内容 ...
- 关于一个软件ipa包的其他图片资源
有时候 当你打开一个ipa包内容的时候 可能会找不到全部的资源 所以你需要在github上下载一个插件 下载下来以后 运行一下 然后会出来这个 把ipa 文件 拖到里面 ...