/**
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的更多相关文章

  1. DP ZOJ 3872 Beauty of Array

    题目传送门 /* DP:dp 表示当前输入的x前的包含x的子序列的和, 求和方法是找到之前出现x的位置(a[x])的区间内的子序列: sum 表示当前输入x前的所有和: a[x] 表示id: 详细解释 ...

  2. 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 ...

  3. 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 ...

  4. ZOJ 3872 Beauty of Array DP 15年浙江省赛D题

    也是一道比赛时候没有写出来的题目,队友想到了解法不过最后匆匆忙忙没有 A 掉 What a pity... 题意:定义Beauty数是一个序列里所有不相同的数的和,求一个序列所有字序列的Beauty和 ...

  5. ZOJ 3872 Beauty of Array (The 12th Zhejiang Provincial Collegiate Programming Contest )

    对于没有题目积累和clever mind的我来说,想解这道题还是非常困难的,也根本没有想到用dp. from: http://blog.csdn.net/u013050857/article/deta ...

  6. Zoj 3842 Beauty of Array

    Problem地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5520 根据题目的要求,需要算出所有连续子数组的the be ...

  7. ZOJ 3872: Beauty of Array(思维)

    Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...

  8. 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 ...

  9. ZOJ 3872 浙江2015年省赛试题

    D - Beauty of Array Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu S ...

随机推荐

  1. Windows下父进程监视子进程状态

    最近研究自动化测试,需要获取程序的运行状态及结果,下面是些参考资料. 原文地址:http://blog.csdn.net/ariesjzj/article/details/7226443 Linux下 ...

  2. 最常用的 Eclipse 快捷键总结

    本文是一些最实用.最齐全.最省时间的 Eclipse 快捷键总结,这些快捷键可以让帮助你完成工作中的任何一个操作.欢迎参考. 1. ctrl+shift+r:打开资源 这可能是所有快捷键组合中最省时间 ...

  3. php异步请求模拟多进程

    在A请求页面发起另一个B页面请求 不需要等待B页面执行结束再返回 直接往下执行A页面的请求 A页面代码 <?php $url = 'http://'.$_SERVER['HTTP_HOST']. ...

  4. bzoj2658: [Zjoi2012]小蓝的好友(mrx)

    太神辣 treap的随机键值竟然能派上用场.. 要用不旋转的treap来进行维护区间信息 #include<cstdio> #include<cstring> #include ...

  5. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(17)-LinQ动态排序

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(17)-LinQ动态排序 首先修复程序中的一个BUG这个BUG在GridPager类中,把sord修改为s ...

  6. JAVA 内存泄露的理解

    1 什么是内存泄露? 内存泄露是指没用的对象持续占有内存空间,造成内存空间浪费.所以说JAVA是有内存泄露的. 2 内存泄露的原因是什么? 较长生命周期对象持有短生命周期对象的引用,导致短生命周期对象 ...

  7. delphi TFontDialog

      设置前先获得Memo的字体属性并设置给FontDialog 然后再设置MEMO的字体属性   //设置Memo的字体属性 procedure TForm1.mni_FontClick(Sender ...

  8. android 04 AbsoluteLayout

    绝对布局:layout_x,layout_y:坐标精准定位 xml文件:不推荐使用 <AbsoluteLayout xmlns:android="http://schemas.andr ...

  9. TCP SOCKET中backlog参数的用途是什么? ---图解

    recv_queue中的包大小,为内核的包大小,而不是ip包大小. 如果发出去的包太大,需要修改write_queue和tx_queue两个参数,tx_queue主要是流量控制. 多进程必须在sock ...

  10. A different twist on pre-compiling JSPs--reference

    I’ve blogged about this topic earlier and expressed my frustrations as to how web containers don’t p ...