ZOJ 3872 - Team Formation(DP)
来源:互联网 发布:linux编辑hosts 编辑:程序博客网 时间:2024/06/06 03:36
题目:
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3872
题意:
求出序列中元素不相同的子序列的总和。
思路:
记录上一个出现x的位置 b[a].
res += (i-b[a])*a;
AC.
#include <iostream>#include <cstdio>#include <cstring>using namespace std;typedef long long ll;int b[1000005];int main(){ //freopen("in", "r", stdin); int T; scanf("%d", &T); while(T--) { int n, a; ll ans = 0, res = 0; scanf("%d", &n); memset(b, 0, sizeof(b)); for(int i = 1; i <= n; ++i) { scanf("%d", &a); res = res + (i-b[a])*a; b[a]= i; ans += res; } printf("%lld\n", ans); } return 0;}
0 0
- ZOJ 3872 - Team Formation(DP)
- ZOJ 3870 Team Formation(数学)
- ZOJ 3870 Team Formation(异或)
- ZOJ 3870 Team Formation(位运算)
- ZOJ 3870 - Team Formation(数学)
- ZOJ 3870Team Formation(位运算)
- ZOJ 3933 Team Formation (km算法)
- ZOJ - 3870 Team Formation (位运算)
- ZOJ 3870 Team Formation (二进制)
- ZOJ-3870 Team Formation(位运算)
- ZOJ 3870 Team Formation
- ZOJ 3870 Team Formation
- ZOJ 3870 Team Formation
- zoj #3870:Team Formation
- ZOJ 3870 Team Formation
- ZOJ-3870-Team Formation
- ZOJ-3870 Team Formation
- ZOJ 3870 Team Formation (The 12th Zhejiang Provincial Collegiate Programming Contest 数位DP+二分)
- phpstorm8连接xdebug来调试php
- java.sql.SQLException: The Network Adapter could not establish the connection
- markdown pad2破解
- SOJ3423: Revamping Trails--(最短路 + 动态规划)
- 数组、方法和字符串 - 1
- ZOJ 3872 - Team Formation(DP)
- Linux 创建快捷方式
- 仿QQ概念版的登陆界面
- 电子元器件-------电阻(R)
- 《Thinking in JAVA》读书笔记_第二章_2.1
- HDU 2013 2014 2015 2016
- ARM处理器模式
- mysql数据库的连接和操作
- 真实世界中的 Rails,第 3 部分: 优化 ActiveRecord