算法设计与分析书中程序(第05章).docVIP

  • 0
  • 0
  • 约5.53千字
  • 约 6页
  • 2015-08-23 发布于安徽
  • 举报
【程序5-1】 分治法 SolutionType DandC(ProblemType P) { ProblemType P1,P2,(,Pk; if (Small(P)) return S(P); //子问题P足够小,用S(P)直接求解 else { Divide(P,P1,P2,(,Pk); //将问题P分解成子问题P1, P2, …, Pk Return Combine(DandC(P1),DandC(P2),…,DandC(Pk));//求解子问题,并合并解 } } 【程序5-2】 一分为二的分治法 SolutionType DandC(int left,int right) { if (Small(left,right)) return S(left,right); else { int m=Divide(left,right); //以m为界将问题分解成两个子问题 Return Combine(DandC(left,m),DandC(m+1,right)); //分别求解子问题,并合并解 } } 【程序5-3】 可排序表类 template class K, class D struct E { //可排序表中元素的类型 operator K()const { return key;} //重载类

文档评论(0)

1亿VIP精品文档

相关文档