scu oj 4441 Necklace(dp+树状数组)(*)
来源:互联网 发布:利率敏感性缺口 数据 编辑:程序博客网 时间:2024/05/17 11:05
题目链接
Necklace
frog has n gems arranged in a cycle, whose beautifulness are a1,a2,…,an. She would like to remove some gems to make them into a beautiful necklace without changing their relative order.
Note that a beautiful necklace can be divided into 3 consecutive parts X,y,Z, where
- X consists of gems with non-decreasing beautifulness,
- y is the only perfect gem. (A perfect gem is a gem whose beautifulness equals to 10000)
- Z consists of gems with non-increasing beautifulness.
Find out the maximum total beautifulness of the remaining gems.
Input
The input consists of multiple tests. For each test:
The first line contains 1 integer n (1≤n≤105). The second line contains n integers a1,a2,…,an. (0≤ai≤104, 1≤number of perfect gems≤10).
Output
For each test, write 1 integer which denotes the maximum total remaining beautifulness.
Sample Input
6 10000 3 2 4 2 3 2 10000 10000
Sample Output
10010 10000
题意:N个数构成一个环,现在可以删除一些数,使得这个环可以分成连续的三部分:
X部分:所有数不降
Y部分:仅含一个值为10000的数
Z部分:所有数不增
(X,Y中不含值为10000的数),值为10000的数不超过10个。
求满足条件的环中,剩余数字的和最大为多少?
题解:枚举值为10000的数。确定值为10000的数的位置后,环就断成了一条链。我们可以用动态规划求出(1,i)的数的不增序列的最大和,同理求出(i,n)的不增序列的最大和。然后枚举断点即可。在动态规划的过程中需要用到树状数组优化转移(线段树为T)。
代码如下:
- scu oj 4441 Necklace(dp+树状数组)
- scu oj 4441 Necklace(dp+树状数组)(*)
- scu oj 4441 Necklace(dp+树状数组求上升序列最大和)
- scu oj 4441 Necklace 2015年四川省赛F题(dp+数据结构)
- HDU3874 Necklace(树状数组)
- CSU 4441 Necklace (树状数组/LIS)
- HDU 3874 Necklace(树状数组)
- hdu-3874-Necklace-(树状数组)
- HDU3874 Necklace[树状数组]
- Necklace(树状数组)
- Light OJ 1402 (Dp + 树状数组)
- HDU 3874 Necklace 树状数组
- HDU 3874 Necklace (树状数组)
- Hdu 3874 Necklace 树状数组
- hdu 3874 Necklace (树状数组)
- hdu 3874 Necklace(树状数组的灵活应用)
- HDU 3874 Necklace(树状数组离线处理)
- HDU 3874 Necklace(树状数组 && 离线操作)
- Java设计模式:观察者模式(Observer Pattern)续
- 大约已经是第五次重装Ubuntu了
- pyspider的使用
- Gym
- Spring MVC
- scu oj 4441 Necklace(dp+树状数组)(*)
- 归并排序求逆序对
- PAT1003. 我要通过!
- Wayland与Weston简介
- GIT工作流
- Cocos2dx中类库中Vector<T>容器的使用
- Value使用
- 提升网站权重的SEO优化基础,你会吗?
- 免费全功能响应式模板:黑暗元素