to calculate the min step of multiplicate some matixs

 package dynamic_programming;

 public class matrix_chain_order { //input is a sequence p = p0,p1..pn,where p.length = n+1  (matrix n is pn-1pn)
int[] p;
int[][] cost;
public matrix_chain_order(int[] a){
p = a;
}
public int order(){
int q = 0;
int n = p.length -1;
cost = new int[n][n];
for(int i = 0;i<= n-1;i++){
cost[i][i] = 0;
}
for(int l = 2;l<n;l++){ //the chain length,like merge sort
for(int i=0;i<n-l;i++){
int j = i+l -1;
cost[i][j] =Integer.MAX_VALUE;
for(int k = i;k <=j -1;k++){
q = cost[i][k] + cost[k+1][j] + p[i-1]*p[k]*p[j];
if(q < cost[i][j]){
cost[i][j] = q; //remeber the best step of i to j
}
}
}
}
return cost[n-1][n-1];
} }

最新文章

  1. 继承映射关系 TPH、TPT、TPC&lt;EntityFramework6.0&gt;
  2. easyUI 中datagrid 返回列隐藏方法
  3. 关于flume配置加载
  4. ACM zb的生日
  5. [css]需警惕CSS3属性的书写顺序
  6. Redis设计思路学习与总结
  7. IIS7 / IIS7.5 URL 重写 HTTP 重定向到 HTTPS(转)
  8. 用PHP添加购物商品
  9. Js实现简单的联动,无数据库版本
  10. Android传感器编程带实例(转)
  11. CentOS7.2静默安装oracle11g
  12. 升级安装php7要考虑的几个方面
  13. 用eNSP模拟
  14. Elastic Stack之kibana入门
  15. Swift4.0 从相册中获取图片和拍照
  16. 线性代数导论 | Linear Algebra 课程
  17. java获取泛型类型
  18. [Laravel] 08 - Auth &amp; Data Migration
  19. https://blog.csdn.net/dayancn/article/details/54692111
  20. chorem浏览器无法下载

热门文章

  1. ansible常用命令大全
  2. Java连接数据库 #06# SQL与代码分离(精化版本)
  3. iptables 初见 第一章
  4. Splay详解
  5. JS设计模式(10)职责链模式(重要)
  6. 剑指offer(36)两个链表中的第一个公共节点
  7. Java调用第三方接口示范
  8. Learning-Python【21】:Python常用模块(4)—— re、logging、hashlib、subprocess
  9. vue--实例化对象
  10. P1908 逆序对