ZOJ14省赛3872——DP——Beauty of Array
2015-04-26 15:39
489 查看
140-The12thZhejiangProvincialCollegiateProgrammingContest-D
BeautyofArrayTimeLimit:2SecondsMemoryLimit:65536KB
EdwardhasanarrayAwithNintegers.Hedefinesthebeautyofanarrayasthesummationofalldistinctintegersinthearray.NowEdwardwantstoknowthesummationofthebeautyofallcontiguoussubarrayofthearrayA.
ThefirstlinecontainsanintegerN(1<=N<=100000),whichindicatesthesizeofthearray.ThenextlinecontainsNpositiveintegersseparatedbyspaces.Everyintegerisnolargerthan1000000.
ViewCode
BeautyofArrayTimeLimit:2SecondsMemoryLimit:65536KB
EdwardhasanarrayAwithNintegers.Hedefinesthebeautyofanarrayasthesummationofalldistinctintegersinthearray.NowEdwardwantstoknowthesummationofthebeautyofallcontiguoussubarrayofthearrayA.
Input
Therearemultipletestcases.ThefirstlineofinputcontainsanintegerTindicatingthenumberoftestcases.Foreachtestcase:ThefirstlinecontainsanintegerN(1<=N<=100000),whichindicatesthesizeofthearray.ThenextlinecontainsNpositiveintegersseparatedbyspaces.Everyintegerisnolargerthan1000000.
Output
Foreachcase,printtheanswerinoneline.SampleInput
3 5 12345 3 233 4 2332
SampleOutput
105 21 38 大意:给你一组数,让你输出这组数中所有集合的和(如果集合中有两个或两个以上的数,那么只算一个) dp指包括自己的集合总数 sum指结果
#include<cstdio> #include<cstring> #include<algorithm> usingnamespacestd; inta[100001]; intmain() { intn,m,T; scanf("%d",&T); while(T--){ longlongsum,dp; scanf("%d",&n); sum=dp=0; memset(a,0,sizeof(a)); for(inti=1;i<=n;i++){ scanf("%d",&m); dp=(i-a[m])*m+dp; sum+=dp; a[m]=i;//m前面所有的数都不可行 } printf("%d\n",sum); } return0; }
ViewCode
相关文章推荐
- ZOJ 3872-Beauty of Array(递推||DP)
- ZOJ - 3872 —— Beauty of Array —— dp
- ZOJ 3872 Beauty of Array DP 15年浙江省赛D题
- [dp] zoj 3872 Beauty of Array
- DP ZOJ 3872 Beauty of Array
- ZOJ3872 Beauty of Array---规律 | DP| 数学能力
- ZOJ 3872 Beauty of Array(DP)
- ZOJ 3872 Beauty of Array【dp】
- [dp] zoj 3872 Beauty of Array
- ZOJ 3872 Beauty of Array( DP思想 )
- ZOJ 3872 Beauty of Array (思维 dp思想)
- ZOJ 3872 Beauty of Array (The 12th Zhejiang Provincial Collegiate Programming Contest )
- ZOJ Problem Set - 3872||Beauty of Array
- ZOJ 3872 Beauty of Array(数学啊)
- ZOJ 3872 Beauty of Array
- ZOJ 3872 Beauty of Array 动态规划子序列
- ZOJ 3872 Beauty of Array&&ZOJ 3870 Team Formation
- ZOJ 3872 Beauty of Array
- ZOJ 3872 Beauty of Array(模拟)
- ZOJ 3872 — Beauty of Array