HDU3507 print artical】的更多相关文章

题目大意:有N个数字a[N],每输出连续的一串,它的费用是 “这行数字的平方加上一个常数M”.问如何输出使得总费用最小.(n<=500000) 分析:动态规划方程为:dp[i]=dp[j]+M+(sum[i]-sum[j])^2: 右边有一项为:sum[i]*sum[j].考虑用单调队列. 令dp[i]=g,dp[j]+M+sum[i]^2+sum[j]^2=y,sum[j]=y,2*sum[i]=k 则上式变为g=y-kx,即y=kx+g.此为直线方程. 我们要使得g最小,即可以考虑有一条斜率…
题目链接:https://vjudge.net/problem/HDU-3507 Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 14899    Accepted Submission(s): 4648 Problem Description Zero has an old printer that doe…
Zero has an old printer that doesn't work well sometimes. As it is antique, he still like to use it to print articles. But it is too old to work for a long time and it will certainly wear and tear, so Zero use a cost to evaluate this degree. One day…
Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Problem Description Zero has an old printer that doesn't work well sometimes. As it is antique, he still like to use it to print articles. But it is to…
Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 11761    Accepted Submission(s): 3586 Problem Description Zero has an old printer that doesn't work well sometimes. As it is antiqu…
Problem Description Zero has an old printer that doesn't work well sometimes. As it is antique, he still like to use it to print articles. But it is too old to work for a long time and it will certainly wear and tear, so Zero use a cost to evaluate t…
前几天做多校,知道了这世界上存在dp的优化这样的说法,了解了四边形优化dp,所以今天顺带做一道典型的斜率优化,在百度打斜率优化dp,首先弹出来的就是下面这个网址:http://www.cnblogs.com/ka200812/archive/2012/08/03/2621345.html 上面讲的很详细,但是实际上有些地方貌似是不小心写错了,所以我也来复述一下感悟一下收获. 首先题意是比较明确的,如果我们定义dp[i]为打印到第i个字符时的最小花费的话,显然有下面的转移: dp[i]=dp[j]…
pid=3507">传送门 大意:打印一篇文章,连续打印一堆字的花费是这一堆的和的平方加上一个常数M. 首先我们写出状态转移方程 :f[i]=f[j]+(sum[i]−sum[j])2+M;f[i] = f[j] + (sum[i] - sum[j])^2 + M; 设 j 优于 k. 那么有 f[j]+(sum[i]−sum[j])2<f[k]+(sum[i]−sum[k])2f[j] + (sum[i] - sum[j])^2 移项得出 (f[j]+sum[j]2)−(f[k]+…
题目大意:将n个数分成若干个区间,每个区间的代价为区间和的平方加上一个常数m,求最小代价. 题目分析:定义状态dp(i)表示前 i 个数已经分好的最小代价,则状态转移方程为 dp(i)=min(dp(j)+(sum(j)-sum(i))^2)+m   <1>.将这个方程整理一下得到: dp(i)=min(-2*sum(i)*sum(j)+dp(j)+sum(j)^2)+sum(i)^2+m   <2>. 设函数f(i)=-2*sum(i)*sum(j)+dp(j)+sum(j)^2…
传送门 这应该算是斜率优化的模板题了. 就是要求打印n个数,每个数有一个参数a[i],每打印一段连续的数[l,r]需要的花费是(a[[l]+...+a[r])2+m" role="presentation" style="position: relative;">(a[[l]+...+a[r])2+m(a[[l]+...+a[r])2+m,要使得打印出所有数的代价最小. 用dp[i]表示打印1~i用的最小代价,显然有dp[i]=min(dp[j]+m…