HDU 5009】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=5009 题意:一个数列,每个点代表一种颜色,每次选一个区间覆盖,覆盖的代价是区间内颜色种类数的平方,直到覆盖整个数列,求最小花费 思路:首先合并颜色相同的点,接着离散化颜色,做dp,dp[i]表示取到位置i的最小花费,注意到答案最大值应该是合并后的数列长度,这是一个剪枝,为了避免每次循环memset vis数组,要把每次访问的颜色值记录在一个vector中,然后只清vector内的颜色清空vector 即可 这…
http://acm.hdu.edu.cn/showproblem.php?pid=5009 有一段序列,涂连续一段子序列的代价为该子序列出现不同数字个数的平方,求最小代价涂完整个序列. ai有10^9,所以先进行离散化 复杂度有n^2,需要剪枝,就是如果答案大于了dp[n]就不用往后继续转移了,这样复杂度就变成了O(n√n) vector用的姿势不对会T #include <cstdio> #include <cstdlib> #include <cmath> #in…
转自:http://blog.csdn.net/accelerator_/article/details/39271751 吐血ac... 11668627 2014-09-16 22:15:24 Accepted 5009 1265MS 1980K 2290 B G++ czy   Paint Pearls Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Subm…
Paint Pearls 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 e…
首先把具有相同颜色的点缩成一个点,即数据离散化. 然后使用dp[i]表示涂满前i个点的最小代价.对于第i+1个点,有两种情况: 1)自己单独涂,即dp[i+1] = dp[i] + 1 2)从第k个节点之后(不包括k)到第i+1个节点一次涂完,且一起涂的节点共有num种颜色,即dp[i+1] = dp[k] + num * num 从而可以得到状态转移方程dp[i+1] = min(dp[i], dp[k] + num * num) 但是如果从后往前遍历每一个k,会超时. 因此我们可以使用双向链…
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,…
2014 ACM/ICPC Asia Regional Xi'an Online 对于N个数 n(1 ≤ n ≤ 5×104), 把N个数分成随意个区间,每一个区间的值是该区间内不同数字个数的平方和,答案使和最小 DP思路,首先要对数据合并相连同样数字,然后离散化. 数据太弱了.... . 然后直接做N*N的DP居然能AC. . ..比赛时候想到了.. .不敢写. .. G++AC C++TLE #include "stdio.h" #include "string.h&qu…
Paint Pearls 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 ea…
Paint Pearls 思路: 离散化+dp+剪枝: dp是个n方的做法: 重要就在剪枝: 如果一个长度为n的区间,有大于根号n种颜色,还不如一个一个涂: 来,上代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 50005 int n,ai[maxn],dp[maxn],ls[…
DP其实也是和搜索一样可以有剪枝的,昨晚看到一个超级好的DP剪枝题:(HDU - 5009) N段东东,要染色,每次给一个区间染色需要的花费为  该区间颜色总数的平方.  每一段只能被染一次色.求 最少花费将所有区间染色. N<=500000; 这题也是很容易想到方程:F[j] 表示前i段的最小花费,F[j]=min{F[k]+sum[k+1][j]} (k<i) .  复杂度为O(N^2),但是数据范围大的BT..所以需要优化.而本题貌似没法用一个辅助数组来草..所以需要从题目本身的限制条件…