HDU 5496 Beauty of Sequence
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5496
Beauty of 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}.
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.
5
1 2 3 4 5
4
1 2 1 3
5
3 3 2 1 2
54
144
题意分析:
题目 是让我们求所有子序和的总和,并且在一个子序列中相邻且相等的数不重复累加(相当于当成一个数)。
题解:
当你一个问题想不通的时候,可以换一个角度来思考。
一开始直接想统计结果,但是明显统计量是天文数字,于是觉得是不是有什么规律,也没想出来,于是就想从反面思考这个问题,既然不能直接求和,那么能不能转而去求每个点对最后的ans的贡献呢。小试了一下,发现可行。
另外一个问题,在一个子序列中相邻相同点只考虑一次。可以选择在这样的子序列中只计算第一个点的贡献值。也就是,考虑一个点的贡献值,只要考虑那些包含它且在它前面没有与它相等的点的所有子序列,我们可以换个角度去求这样的子序列个数,统计所有包含改节点的子序列,然后减去不符合条件的子序列(具体看代码注释)

ac代码:
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
typedef long long LL; const int maxn = 1e5 + ;
const int mod = 1e9 + ; int a[maxn];
int n; int bin[maxn];
map<int, int> mymap; void table() {
bin[] = ;
for (int i = ; i < maxn; i++) bin[i] = bin[i - ] * % mod;
} void init() {
mymap.clear();
} int main() {
int tc;
table();
scanf("%d", &tc);
while (tc--) {
init();
scanf("%d", &n);
LL ans = ;
for (int i = ; i <= n; i++) {
scanf("%d", a + i);
//mymap[a[i]]表示在i之前,所有以a[i]结尾的子序列的数目
//bin[n-1]表示所有包含i的子序列,而mymap[a[i]]*bin[n-i]代表的就是不符合条件的子序列了。
LL tmp = ((bin[n - ] - (LL)bin[n - i] * mymap[a[i]])%mod +mod) % mod;
ans = (ans + a[i] * tmp) % mod;
mymap[a[i]] += bin[i - ];
mymap[a[i]] %= mod;
}
printf("%lld\n", ans);
}
return ;
}
HDU 5496 Beauty of Sequence的更多相关文章
- Hdu 5496 Beauty of Sequence (组合数)
题目链接: Hdu 5496 Beauty of Sequence 题目描述: 一个整数序列,除去连续的相同数字(保留一个)后,序列的和成为完美序列和.问:一个整数序列的所有子序列的完美序列和? 解题 ...
- HDU 5496——Beauty of Sequence——————【考虑局部】
Beauty of Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- hdu-5496 Beauty of Sequence(递推)
题目链接: Beauty of Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java ...
- 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...
- hdu 4893 Wow! Such Sequence!(线段树)
题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...
- Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)
Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...
- HDU 5063 Operation the Sequence(暴力)
HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...
- HDU 5288 OO’s Sequence [数学]
HDU 5288 OO’s Sequence http://acm.hdu.edu.cn/showproblem.php?pid=5288 OO has got a array A of size ...
随机推荐
- php向页面输出中文时出现乱码的解决方法
今天,刚刚学习PHP发现用echo输出中文时,页面会出现乱码,然后查了一下资料说是浏览器编码格式有问题,要改成utf-8.但是每个人的浏览器编码可能会有所不同,所以找到了一个很好的解决方法, 就是在p ...
- Python用@property使类方法像属性一样访问
class Screen(object): @property #读取with的值getter方法 def width(self): return self._width @width.setter ...
- 教你解决Xshell用SSH连接ubuntu总掉线该
使用Xshell 5中的SSH连接ubuntu总是掉线,搞的自己束手无策,本集小编整理了一下原因及解决方法,现晒出来和大家分享一下,希望可以帮助大家. 1. Xshell客户端设置 将Keep Ali ...
- 20155202 《Java程序设计》实验一(Java开发环境的熟悉)实验报告
20155202 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 一.实验内容及步骤 使用JDK编译.运行简单的java程序 命令行下的程序开发 一(新建文件夹): 打开wi ...
- WPF MVVM从入门到精通5:PasswordBox的绑定
原文:WPF MVVM从入门到精通5:PasswordBox的绑定 WPF MVVM从入门到精通1:MVVM模式简介 WPF MVVM从入门到精通2:实现一个登录窗口 WPF MVVM从入门到精通 ...
- Discover Feature Engineering, How to Engineer Features and How to Get Good at It
Feature engineering is an informal topic, but one that is absolutely known and agreed to be key to s ...
- L015-linux系统文件权限体系手把手详解小结
L015-linux系统文件权限体系手把手详解小结 2016-5-24 今天星期二,昨天和今天利用一些闲散时间把第15节课学完了,最近有点懒散哈,还得努力才是.. 这节课内容不多,扩展的也少,主要就是 ...
- 180726-InfluxDB基本概念小结
InfluxDB基本概念小结 InfluxDB作为时序数据库,与传统的关系型数据库相比而言,还是有一些区别的,下面尽量以简单明了的方式介绍下相关的术语概念 I. 基本概念 mysql influxdb ...
- python的pip升级问题
近来由于pip升级为10.0.1了,导致使用pip命令报错,使用过很多方法,最终找到一种相对靠谱的方法,一下是步骤: 进入https://pypi.python.org/pypi/pip 下载pip- ...
- Phaser3 屏幕适配iPhoneX、iPhoneXs的坑 -- JavaScript Html5 游戏开发
PhaserJS 坑:在config内不要把 width 设为 window.innnerWidth在config内不要把 width 设为 window.innnerWidth在config内不 ...