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

对于没有题目积累和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;  
}  



 

posted @ 2015-04-28 11:35  Traveller_Leon  阅读(137)  评论(0)    收藏  举报