动态规划之四边形不等式和斜率优化

动态规划之四边形不等式和斜率优化

ID:18472299

大小:69.00 KB

页数:6页

时间:2018-09-18

动态规划之四边形不等式和斜率优化_第1页
动态规划之四边形不等式和斜率优化_第2页
动态规划之四边形不等式和斜率优化_第3页
动态规划之四边形不等式和斜率优化_第4页
动态规划之四边形不等式和斜率优化_第5页
资源描述:

《动态规划之四边形不等式和斜率优化》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、1四边形不等式优化对于转移如果满足:存在s[i][j]的转移:最后转移:1.1例题:hdu3480划分问题DivisionProblemDescriptionLittleDisreallyinterestedinthetheoremofsetsrecently.There’saproblemthatconfusedhimalongtime.  LetTbeasetofintegers.LettheMINbetheminimumintegerinTandMAXbethemaximum,thenthecostofset

2、Tifdefinedas(MAX–MIN)^2.NowgivenanintegersetS,wewanttofindoutMsubsetsS1,S2,…,SMofS,suchthatandthetotalcostofeachsubsetisminimal.InputTheinputcontainsmultipletestcases.Inthefirstlineoftheinputthere’sanintegerTwhichisthenumberoftestcases.ThenthedescriptionofTtes

3、tcaseswillbegiven.Foranytestcase,thefirstlinecontainstwointegersN(≤10,000)andM(≤5,000).NisthenumberofelementsinS(maybeduplicated).Misthenumberofsubsetsthatwewanttoget.Inthenextline,therewillbeNintegersgivingsetS.OutputForeachtestcase,outputonelinecontainingexa

4、ctlyoneinteger,theminimaltotalcost.Takealookatthesampleoutputforformat.SampleInput2321244247101SampleOutputCase1:1Case2:1分析:1)dp[i][j]表示前i个数字,分成j份的最小值2)dp[i][j]=min(dp[k][j-1]+w[k+1][j])(i<=k

5、e#include#includeusingnamespacestd;#defineN10001#defineM5001constintINF=0x7fffffff;inlineintsqr(intx){returnx*x;}intn,m;inta[N];intdp[N][M];ints[N][M];intcal(){if(n<=m)return0;sort(a+1,a+1+n);for(inti=0;i<=n;++i)for(intj=0;j<=m;++j)

6、dp[i][j]=-1;dp[0][0]=0;for(inti=1;i<=n;++i){intmaxj=min(i,m);intmn=INF,mk;for(intk=0;k=1;--j){intmn=INF,mk;for(intk=s[i-1

7、][j];k<=s[i][j+1];++k)if(dp[k][j-1]!=-1){inttmp=dp[k][j-1]+sqr(a[i]-a[k+1]);if(tmp

8、Case%d:%d",++cas,cal());}return0;}1.2例题hdu3506合并问题MonkeyPartyProblemDescriptionFarawayfromourworld,thereisabananaforest.Andmanylovelymonkeyslivethere.Oneday,SDH(SongDaHou),whoist

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。