HDU 5496 - BestCoder Round #58 - Beauty of Sequence
思路 :
考虑这个序列当前的第i个数能有几种组合方法, 前面有2^(i-1)种, 后面有有2^(n-i)种, 本来答案是a[i] * 2^(n-1), 但要求对于某种排列存在相邻且相等的数是不计入答案的
例如 第二组样例 1 2 1 3, 1 1 3中1重复故要减去一个1
可见, 只有前一个数和a[i]相等时, a[i]就不能计入了, 而后面和a[i]相等便可以计入(后面和a[i]相等时, 可以看作约去后面的值, 这一种方法对a[i]这个值依然有1个贡献)
所以关键就是得到第i个数, 前面有几种以a[i]结尾的方法, 设为k, 这是要减去的方法数, a[i]的贡献就是a[i] * 2^(n-i) *[2^(n-i) - k]
方法 :
2的幂次预处理到10^5
对于得到k, 可以用map + 前缀和的形式记录, 例如当前位置i, 第一次得到一个a[i], 那么以这个数结尾有2^(i-1)种方法, 第二次在j位置得到了a[j] = a[i]
那么以a[i]结尾的就变成了2^(i-1) + 2^(j-1)种
比赛的时候没想到用map记录, n^2完全不敢写, 太弱了= =
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map> using namespace std; typedef long long LL; const int MAXN = 1e5+;
const int MOD = 1e9+; map<int, LL> r;
int a[MAXN];
int f[MAXN];
int Pow[MAXN]; void Pre()
{
Pow[] = ;
for(int i = ; i < MAXN; i++) {
Pow[i] = (Pow[i-] << ) % MOD;
}
} void Init()
{
r.clear();
} int main()
{
Pre(); int t;
int n; scanf("%d", &t);
while(t--) {
Init();
scanf("%d", &n);
for(int i = ; i < n; i++) {
scanf("%d", &a[i]);
f[i] = (LL)Pow[n-i-] * (Pow[i] - r[a[i]] + MOD) % MOD;
r[a[i]] += Pow[i];
r[a[i]] %= MOD;
}
LL ans = ;
for(int i = ; i < n; i++) {
ans += (LL)a[i] * f[i];
ans %= MOD;
}
printf("%I64d\n", ans);
} return ;
}
HDU 5496 - BestCoder Round #58 - Beauty of Sequence的更多相关文章
- hdu 5667 BestCoder Round #80 矩阵快速幂
Sequence Accepts: 59 Submissions: 650 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- hdu 5643 BestCoder Round #75
King's Game Accepts: 249 Submissions: 671 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6 ...
- hdu 5641 BestCoder Round #75
King's Phone Accepts: 310 Submissions: 2980 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- HDU 5682/BestCoder Round #83 1003 zxa and leaf 二分+树
zxa and leaf Problem Description zxa have an unrooted tree with n nodes, including (n−1) undirected ...
- HDU 5506 - BestCoder Round #60 - GT and set
题目链接 : http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=641&pid=1003 题意 : 给N集 ...
- HDU 5505 - BestCoder Round #60 - GT and numbers
题目链接 : http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=641&pid=1002 思路 : N有若 ...
- HDU 5568 - BestCoder Round #63 - sequence2
题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=5568 题意 : 给一个长度已知的序列, 给一个值k, 问该序列中有多少种长度为k的上升子序列 思路 ...
- hdu 5637 BestCoder Round #74 (div.2)
Transform Accepts: 7 Submissions: 49 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072 ...
- hdu 5600 BestCoder Round #67 (div.2)
N bulbs Accepts: 275 Submissions: 1237 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 655 ...
随机推荐
- Spring-----1、Spring一个简短的引论
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGVrZXdhbmd6aQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- Difference between Tomcat's extraResourcePaths and aliases to access an external directory--转
Question: Simple question: In Tomcat7, what's the difference between using extraResourcePaths and al ...
- 用switch判断月份的练习
import java.util.Scanner; public class SwitchTest01 { public static void main(String[] args) { Syste ...
- linux 声音大小调整的命令
alsamixer 输入上面的命令 回车即可看到图形界面,界面如下 ┌──────────────────────────── AlsaMixer v1.0.27.1 ──────────────── ...
- C#学习(三)
通过类创建对象的过程称为类的实例化 匿名类型提供了一种方便的方法,可用来将一组只读属性封装到单个对象中,而无需首先显式定义一个类型. 要将匿名类型或包含匿名类型的集合作为参数传递给某一方法,可将参数作 ...
- 腾讯云升级到PHP7
1.删除之前安装的PHP yum remove php* php-common 2.安装yum源 rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel ...
- Android--------使用gson解析json文件
##使用gson解析json文件 **json的格式有两种:** **1. {}类型,及数据用{}包含:** **2. []类型,即数据用[]包含:** 下面用个例子,简单的介绍gson如何解析jso ...
- tips [终端]
pbcopy 命令:Place standard output in the clipboard. $ pbcopy < ~/.ssh/id_rsa.pub
- iOS中忽略NSLog打印信息(通过PCH文件中定义DEBUG宏解决)
iOS中忽略NSLog打印信息 解决办法: 1.新建PrefixHeader_pch文件,在该文件中定义一下宏 //通过DEBUG宏的定义来解决Debug状态下和Release状态下的输出 #ifde ...
- NetBeans使用技巧记录
1.窗体字体大小设置: 在etc文件夹下的netbeans.conf中添加,12表示字体大小,12正合适. netbeans_default_options="--fontsize 12 - ...