zoj 3872 Beauty of Array (数学题)
来源:互联网 发布:night changes知乎 编辑:程序博客网 时间:2024/06/07 19:55
题意:
给出一个序列,然后问这个序所有子序列对应数值的和是多少,注意这个和是序列中不同的数的和。
题解:
这题我们可以这样分析,对于某个数,考虑这个数对总的结果的贡献是多少,于是根据这个方向去思考,加上一些实例的判断,发现可以用递推去求解。
#include<iostream>#include<math.h>#include<stdio.h>#include<algorithm>#include<string.h>#include<vector>#include<queue>#include<map>#include<set>#define B(x) (1<<(x))using namespace std;typedef long long ll;typedef unsigned long long Ull;void cmax(int& a,int b){ if(b>a)a=b; }void cmin(int& a,int b){ if(b<a)a=b; }void cmax(ll& a,ll b){ if(b>a)a=b; }void cmin(ll& a,ll b){ if(b<a)a=b; }void add(int& a,int b,int mod){ a=(a+b)%mod; }void add(ll& a,ll b,ll mod){ a=(a+b)%mod; }const int oo=0x3f3f3f3f;const ll MOD=100000007;const int maxn = 1000005;int pre[maxn];int main(){ int n,T; scanf("%d",&T); while(T--){ scanf("%d",&n); memset(pre,0,sizeof pre); ll ans=0,sum=0,a; for(int i=1;i<=n;i++){ scanf("%d",&a); sum+=(i-pre[a])*a; ans+=sum; pre[a]=i; } cout<<ans<<endl; } return 0;}
0 0
- zoj 3872 Beauty of Array (数学题)
- ZOJ 3872Beauty of Array
- ZOJ 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 3872 Beauty of Array(数学)
- ZOJ 3872 — Beauty of Array
- [dp] zoj 3872 Beauty of Array
- ZOJ Problem Set - 3872||Beauty of Array
- 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 (技巧)
- [dp] zoj 3872 Beauty of Array
- IOS学习3——AppDelegate .m文件
- 做自己的贵人-作品展有感(1)
- zoj 3870 Team Formation (数位统计问题)
- Java第5天
- activity的生命周期
- zoj 3872 Beauty of Array (数学题)
- 跨越边界: Rails 迁移
- UVA 473-Raucous Rockers(DP)
- JDBC-数据库的编程(一)
- Count Primes
- 5.17
- SQL Server数据库开发的21条军规
- #第47天#健身#
- MOOC Linux内核之旅小结