ZOJ 3872 Beauty of Array


/**
Author: Oliver
ProblemId: ZOJ 3872 Beauty of Array
*/
/*
需求:
求beauty sum,所谓的beauty要求如下:
1·给你一个集合,然后把所有子集合的美丽和求出来;
2·上例子,2.3.3.->2. 3. 3. 2.3. 3. 2.3.
思路:
1·既然要连续的,暴力也会爆,那么自然而然的优化,朝着递推想一下;
2·哥们把之前的算好了,那我们是不是可以用算好的值来求现在的的需要呢;
3·想好了,但是过程我不造该怎么说;
步骤: 。。。
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXM = +;
const int MAXN = +;
int F[MAXN],a[MAXM];
int main()
{
int n,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
memset(F,,sizeof F);
long long ans=,sum=;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(F[a[i]])sum-=F[a[i]]*a[i];
ans+=sum+=i*a[i]; F[a[i]]=i;
}
printf("%lld\n",ans);
}
}
ZOJ 3872 Beauty of Array的更多相关文章
- DP ZOJ 3872 Beauty of Array
题目传送门 /* DP:dp 表示当前输入的x前的包含x的子序列的和, 求和方法是找到之前出现x的位置(a[x])的区间内的子序列: sum 表示当前输入x前的所有和: a[x] 表示id: 详细解释 ...
- ZOJ 3872 Beauty of Array【无重复连续子序列的贡献和/规律/DP】
Edward has an array A with N integers. He defines the beauty of an array as the summation of all dis ...
- ZOJ 3872 Beauty of Array 连续子序列求和
Edward has an array A with N integers. He defines the beauty of an array as the summation of all dis ...
- ZOJ 3872 Beauty of Array DP 15年浙江省赛D题
也是一道比赛时候没有写出来的题目,队友想到了解法不过最后匆匆忙忙没有 A 掉 What a pity... 题意:定义Beauty数是一个序列里所有不相同的数的和,求一个序列所有字序列的Beauty和 ...
- ZOJ 3872 Beauty of Array (The 12th Zhejiang Provincial Collegiate Programming Contest )
对于没有题目积累和clever mind的我来说,想解这道题还是非常困难的,也根本没有想到用dp. from: http://blog.csdn.net/u013050857/article/deta ...
- Zoj 3842 Beauty of Array
Problem地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5520 根据题目的要求,需要算出所有连续子数组的the be ...
- ZOJ 3872: Beauty of Array(思维)
Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...
- ZOJ 3872 浙江2015年省赛试题
D - Beauty of Array Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu S ...
随机推荐
- [转]让程序在崩溃时体面的退出之SEH
原文地址:http://blog.csdn.net/starlee/article/details/6636723 SEH的全称是Structured Exception Handling,是Wind ...
- Error: rpmdb open failed
yumrpmdb: Thread/process 17132/140266190264064 failed: Thread died in Berkeley DB l ...
- Action
学习Action的几个内容 1.实现一个Action的最常用方式: 从ActionSupport继承 链接 2.Action配置 DMI动态方法调用 ! 通配符配置 * {1} {2} … * ...
- 还原dede数据后系统基本参数空白栏目无显示的解决方法
有时dedecms开发的网站在更换空间还原数据后,出现"系统基本参数"空白,而且可以看到tag也没有了. 大家不妨看看后台"数据库备份/还原"处,已经还原后的表 ...
- uva10622 Perfect P-th Powers
留坑(p.343) 完全不知道哪里有问题qwq 从31向下开始枚举p,二分找存在性,或者数学函数什么的也兹辞啊 #include<cstdio> #include<cstring&g ...
- c#语言基础编程-转义符
C#转义字符: 引言 为了在程序中能够控制字符的输出以及区分开双引号和单引号(双引号和单引号在程序中标示里面的内容为字符串和字符),所以用一种特殊的字符常量:是·以反斜线"\"开头 ...
- 在Sql Server 2005中将主子表关系的XML文档转换成主子表“Join”形式的表
本文转载:http://www.cnblogs.com/Ricky81317/archive/2010/01/06/1640434.html 最近这段时间在Sql Server 2005下做了很多根据 ...
- 遍历datatable的几种方法【转载】
遍历datatable的方法2009-- :02方法一: DataTable dt = dataSet.Tables[]; ; i < dt.Rows.Count ; i++) { string ...
- 【Linux常用工具】1.1 diff命令的三种格式
diff是用来比较两个文本文件的差异的工具,它有三种格式,下面用实例介绍一下: 准备三个测试文件1.txt 2.txt 3.txt bixiaopeng@bixiaopengtekiMacBook-P ...
- 通过WriteProcessMemory改写进程的内存
http://www.cnblogs.com/feiyucq/archive/2009/10/21/1587628.html 以PROCESS_ALL_ACCESS权限打开进程以后既能够使用ReadP ...