2014西安网络预选赛1003(DP+剪枝)hdu5009
来源:互联网 发布:手机钢化膜上矩阵小点 编辑:程序博客网 时间:2024/04/29 22:33
Paint Pearls
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 575 Accepted Submission(s): 153
Problem Description
Lee has a string of n pearls. In the beginning, all the pearls have no color. He plans to color the pearls to make it more fascinating. He drew his ideal pattern of the string on a paper and asks for your help.
In each operation, he selects some continuous pearls and all these pearls will be painted to their target colors. When he paints a string which has k different target colors, Lee will cost k2 points.
Now, Lee wants to cost as few as possible to get his ideal string. You should tell him the minimal cost.
In each operation, he selects some continuous pearls and all these pearls will be painted to their target colors. When he paints a string which has k different target colors, Lee will cost k2 points.
Now, Lee wants to cost as few as possible to get his ideal string. You should tell him the minimal cost.
Input
There are multiple test cases. Please process till EOF.
For each test case, the first line contains an integer n(1 ≤ n ≤ 5×104), indicating the number of pearls. The second line contains a1,a2,...,an (1 ≤ ai ≤ 109) indicating the target color of each pearl.
For each test case, the first line contains an integer n(1 ≤ n ≤ 5×104), indicating the number of pearls. The second line contains a1,a2,...,an (1 ≤ ai ≤ 109) indicating the target color of each pearl.
Output
For each test case, output the minimal cost in a line.
Sample Input
31 3 3103 4 2 4 4 2 4 3 2 2
Sample Output
27
题意:每次可以给一个区间涂色,花费为该区间段不同颜色数量的平方,求涂完整个序列的最小花费
思路:DP[i]表示到从1涂到i的最小花费
然后从前往后转移
假设现在由i往后转移,那么转移的时候要枚举从i+1到j的不同颜色的个数x,然后dp[j]=min(dp[j],dp[i]+x*x)
但是要加个剪枝,就是当dp[i]+x*x>=dp[n]时就停止
0 0
- 2014西安网络预选赛1003(DP+剪枝)hdu5009
- 2014西安网络预选赛1009(矩阵快速幂)hdu5015
- 2014西安网络预选赛1009(点分治)HDU5016
- HDU5009西安网赛2014
- 2014西安网络预选赛1002(后缀数组求第K大的子串)hdu5008
- 2014牡丹江网络预选赛D题(状压DP)zoj3812
- 2014鞍山网络预选赛1005(概率DP)hdu5001
- hdu5009 Paint Pearls 西安网络赛C题
- hdu5009 dp
- 2014上海网络预选赛1003(树链剖分)HDU5044
- 2014牡丹江网络预选赛I题(字符串hash+简单DP)zoj3817
- 2016Shenyang网络预选赛1007 / HDU5898 (数位dp)
- hdu5009 Paint Pearls DP
- DP - hdu5009 Paint Pearls
- 2014牡丹江网络预选赛E题(线段树)zoj3813
- 2014牡丹江网络预选赛B题(找规律)zoj3810
- 2014鞍山网络预选赛1006(LCT模板题)hdu5002
- 2014鞍山网络预选赛1004(贪心)hdu5000
- Cocos2dX3.2 对于窗体分辨率的设定
- android知识补充
- 全排列算法(字典序,递归实现)
- spring中的xml配置出现的错误 The Network Adapter could not establish the connection
- coffeescript 汉字转拼音代码
- 2014西安网络预选赛1003(DP+剪枝)hdu5009
- 查找最小的K个元素,使用最大堆。
- mysql 字段操作
- cocos2dx init() 和 onEnter()的区别
- Android 系统启动过程
- 1
- 备忘:Wiki关于Graph数据库信息汇总
- 睁开眼看大神们的C++11
- 数据库第六章小结