ZOJ 3872 Beauty of Array(模拟)
2015-04-30 21:46
113 查看
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3872
题意:求每个连续子序列的和的总和(子序列的和为序列中不重复数字的和)
思路:所有的子序列和(不管重复不重复)减去重复数字所重复的次数
代码:
题意:求每个连续子序列的和的总和(子序列的和为序列中不重复数字的和)
思路:所有的子序列和(不管重复不重复)减去重复数字所重复的次数
代码:
#include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #define LL long long using namespace std; int b[1000005]; int main() { int n,t,i,j,a; LL sum,ans; scanf("%d",&t); while(t--) { sum=ans=0; memset(b,0,sizeof(b)); scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a); if(b[a]) sum-=b[a]*a; sum+=a*i; ans+=sum; b[a]=i; } printf("%lld\n",ans); } return 0; }
相关文章推荐
- 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
- ZOJ Problem Set - 3872 Beauty of Array
- ♥ZOJ 3872-Beauty of Array【规律】
- ZOJ 3872 Beauty of Array
- ZOJ 3872-Beauty of Array(递推||DP)
- ZOJ 3872 Beauty of Array (The 12th Zhejiang Provincial Collegiate Programming Contest )
- ZOJ 3872 Beauty of Array( DP思想 )
- D - Beauty of Array ZOJ - 3872
- DP ZOJ 3872 Beauty of Array
- zoj 3872 Beauty of Array (数学题)
- [dp] zoj 3872 Beauty of Array
- ZOJ 3872 Beauty of Array
- ZOJ 3872 Beauty of Array 动态规划子序列
- ZOJ-3872-Beauty of Array【数学】【12th浙江省赛】
- zoj--3872--Beauty of Array(思维)
- ZOJ 3872 Beauty of Array(DP)