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

来源:互联网 发布:实用办公软件基础教程 编辑:程序博客网 时间:2024/05/14 02:01

对于没有题目积累和clever mind的我来说,想解这道题还是非常困难的,也根本没有想到用dp。

from:

http://blog.csdn.net/u013050857/article/details/45285515

#include <bits/stdc++.h>  using namespace std;  #define LL  unsigned long long  LL a[100010];  int main()  {     int  n,m;     scanf("%d",&n);     while(n--){         scanf("%d",&m);         memset(a,0,sizeof(a));         LL sum=0,dp=0;         for(int i=1;i<=m;i++){             int x;             scanf("%d",&x);             dp=(i-a[x])*x+dp;             sum+=dp;             a[x]=i;         }         printf("%llu\n",sum);     }     return 0;  }  


0 0