Topic Portal
1 /*2 DP:DP represents the and of the sub-sequences containing x before the current input x,3 The summation method is to find the sub-sequences within the interval of the previous occurrence of X (A[x]);4 sum represents all the sum of the current input before x;5 A[x] represents the ID;6 Detailed Explanation:http://blog.csdn.net/u013050857/article/details/452855157 */8#include <cstdio>9#include <algorithm>Ten#include <cmath> One#include <iostream> A#include <cstring> -#include <string> -#include <map> the#include <Set> - using namespacestd; - - Const intMAXN = 1e5 +Ten; + Const intINF =0x3f3f3f3f; - intA[MAXN]; + A intMainvoid)//ZOJ 3872 Beauty of Array at { - //freopen ("d.in", "R", stdin); - - intt, N; -scanf ("%d", &t); - while(t--) in { -Memset (A,0,sizeof(a)); toscanf ("%d", &n); + - intXLong LongDP =0, sum =0; the for(intI=1; i<=n; ++i) * { $scanf ("%d", &x);Panax NotoginsengDP = (I-a[x]) * x +DP; -Sum + =DP; theA[X] =i; + } A theprintf ("%lld\n", sum); + } - $ $ return 0; -}
DP ZOJ 3872 Beauty of Array