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 ...
随机推荐
- Centos6快速yum lamp
yum install httpd httpd-devel mysql mysql-server mysql-devel php php-mysql php-common php-gd php-mb ...
- 爬虫技术浅析 | z7y Blog
爬虫技术浅析 | z7y Blog 爬虫技术浅析
- nyoj 102 次方求模【快速幂】
次方求模 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 求a的b次方对c取余的值 输入 第一行输入一个整数n表示测试数据的组数(n<100)每组测试只有一 ...
- lib_mysqludf_sys的安装过程
看了太多资料,累坏了,先杂乱的放在这里吧,回头有时间再排版 一.window系统 1.从sqlmap中找到32为的 lib_mysqludf_sys.dll (64位的我没有测试成功) 选择数据库 U ...
- 贪心+容器 hdu4268
Problem Description Alice and Bob's game never ends. Today, they introduce a new game. In this game, ...
- 让python输出不自行换行的方法
1,在输出内容后加逗号 例: for i in range(1,6): j = 1 while(j <= 2*i - 1): print "*", ...
- The Boost C++ Libraries
" ...one of the most highly regarded and expertly designed C++ library projects in the world.&q ...
- Swift学习笔记八:枚举
1. 枚举语法 1)枚举的定义 使用enum关键词而且把它们的整个定义放在一对大括号内: enum SomeEumeration { // enumeration definition go ...
- iOS-你真的会用UIMenuController吗?(详细)
UIMenuController的介绍 什么是UIMenuController? UIMenuController是UIKit里面的控件 UIMenuController的作用在开发中弹出的菜单栏 后 ...
- Java设计模式05:常用设计模式之原型模式(创建型模式)
1. Java之原型模式(Prototype Pattern) 原型模式属于对象的创建模式.通过给出一个原型对象来指明所有创建的对象的类型,然后用复制这个原型对象的办法创建出更多同类型的对象. ...