- 浏览: 36263 次
- 性别:
- 来自: 杭州
最新评论
package com.yao.Algorithms; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.Reader; /** * * @author shuimuqinghua77 @date 2011-12-4 * */ public class Problem18 { private final static int SIZE = 100; public static void main(String[] args) throws Exception { /*** * 打开文件triangle.txt 内容如下 * 75 95 64 17 47 82 18 35 87 10 20 04 82 47 65 19 01 23 75 03 34 88 02 77 73 07 63 67 99 65 04 28 06 16 70 92 41 41 26 56 83 40 80 70 33 41 48 72 33 47 32 37 16 94 29 53 71 44 65 25 43 91 52 97 51 14 70 11 33 28 77 73 17 78 39 68 17 57 91 71 52 38 17 14 91 43 58 50 27 29 48 63 66 04 68 89 53 67 30 73 16 69 87 40 31 04 62 98 27 23 09 70 98 73 93 38 53 60 04 23 */ File file = new File("C:\\Users\\Administrator\\Desktop\\triangle.txt"); Reader in = new FileReader(file); BufferedReader br = new BufferedReader(in); /*** * 把文件里面的内容读到数组arr中 */ int[][] arr = new int[SIZE][SIZE]; int lineNum = 0; do { String line = br.readLine(); if (line == null) break; line = line.trim(); String[] str = line.split(" "); for (int j = 0; j < str.length; j++) { arr[lineNum][j] = Integer.parseInt(str[j]); } lineNum++; } while (true); br.close(); in.close(); /** * 动态规划 * 问题Problem18转化求点S(顶点)到 点F(最底端的SIZE个节点)的最大距离中的最大值, * 点A到点B的最大距离,就是点A到点B的父节点(B点有2个父节点)的最大距离+父节点到B的距离。题目转化为层层推进,即一层一层求解 */ int[] premax = new int[SIZE];/**依次存放每一层中的点到顶点的最大值*/ for (int k = 0; k < SIZE; k++) { int[] max = new int[SIZE]; for (int m = 0; m <= k; m++) { if (m == 0) max[m] = arr[k][m] + premax[m]; else { max[m] = premax[m] > premax[m - 1] ? arr[k][m] + premax[m] : arr[k][m] + premax[m - 1]; } } premax = max; } int result = 0; for (int mm : premax) { if (mm > result) result = mm; } System.out.println(result); } }
发表评论
-
Problem26
2013-02-06 17:08 850A unit fraction contains 1 in t ... -
Problem25
2012-04-26 16:33 874package com.yao.Algorithms; ... -
Problem24
2012-04-26 14:12 772package com.yao.Algorithms; ... -
Problem23
2012-03-18 13:29 890A perfect number is a number fo ... -
Problem22
2012-03-17 23:13 757Using names.txt (right click an ... -
Problem21
2012-03-11 20:44 1093Problem 21 05 July 2002 Let ... -
Problem20
2011-12-15 14:09 786package com.yao.shuimu.euler; ... -
Problem19
2011-12-09 14:07 704package com.shui.mu.yao.io.algo ... -
Problem16
2011-12-02 15:32 405package com.shui.mu.yao.io.algo ... -
Problem15
2011-11-29 23:28 516package com.yao.Algorithms; ... -
Problem14
2011-11-29 11:37 690package com.shui.mu.yao.io.algo ... -
Problem13_1
2011-11-21 14:07 567package yao.taobao.jj; publi ... -
Problem13
2011-11-19 23:51 547package com.yao.Algorithms; ... -
Problem12
2011-11-07 20:04 699package com.shui.mu.yao.io.algo ... -
Problem11
2011-11-06 19:38 1179package com.yao.Algorithms; ... -
Problem10
2011-11-03 20:14 393package com.shui.mu.yao.io.algo ... -
Problem9
2011-11-03 16:04 731package com.shui.mu.yao.io.algo ... -
Problem8
2011-11-03 12:38 575package com.shui.mu.yao.io.algo ... -
Problem7
2011-11-03 11:25 432package com.shui.mu.yao.io.algo ...
相关推荐
https://www.luogu.com.cn/problem/P8595 https://www.luogu.com.cn/problem/P8595 https://www.luogu.com.cn/problem/P8595 https://www.luogu.com.cn/problem/P8595 https://www.luogu.com.cn/problem/P8595 ...
标题 "maven3 + jetty 新建webapp" 涉及到的是使用Apache Maven 3构建工具和Jetty轻量级应用服务器来创建一个新的Web应用程序的过程。在Java开发领域,Maven是广泛使用的项目管理和集成工具,它帮助管理项目的构建、...
### ACM新手刷题攻略之POJ ... - 推荐题目:[poj1068](https://vjudge.net/problem/POJ-1068)、[poj2632](https://vjudge.net/problem/POJ-2632)、[poj1573](https://vjudge.net/problem/POJ-1573)、[poj2993]...
https://github.com/Nivedha-Ramesh/Container-Loading-Problem/blob/master/True%20Solution.png https://github.com/Nivedha-Ramesh/Container-Loading-Problem/blob/master/Fitness%20Variation.png ...
leetcode 296 中文网编程题 Java 15 个人练习,部分题目整理提供了多种解法 已完成: 472个 , , , , , 6, , , , 10, , , , , , , , , , , , , , , , , , , 29, 30, , 32, , , , 36, , , , , 41, ...1
Problem Solving with C++, Global Edition by Walter Savitch (author) (Author) Pages:1117 出版社: Pearson Education Limited; 10th edition edition (November 20, 2017) Language: English ISBN-10: ...
Chapter 18. Batch Operating System Chapter 19. Problem of Protection Chapter 20. Timing Program Execution Chapter 21. Efficiency of Batch Operating Systems Chapter 22. Convenience of the BOS Chapter ...
leetcode 答案leetcode 回答
node-problem-detector 镜像包 v0.8.7 版本
### Wicked Problem与Wicked Environmental Problem #### 一、引言 "Wicked Problem"(棘手问题)这一概念最初由霍恩(Horst Rittel)和韦伯(Melvin Webber)于1973年提出,指的是那些复杂且难以解决的问题。这类...
标题 "problem" 提供的信息较少,但从描述中的 "NULL 博文链接:https://eric0000.iteye.com/blog/322311" 可以推测,这可能是一个关于解决某个问题或者技术讨论的博客文章链接。由于没有具体的博文内容,我们无法...
MCM 2012年 problem A problem B problem C 枪手论文
Approaching (Almost) Any Machine Learning Problem是一本旨在帮助读者掌握机器学习问题解决方法的书籍。这本书涵盖了机器学习的基本概念、模型选择、数据预处理、特征工程、模型评估等多方面的知识点。 机器学习...
Codeforces部门2,A # And a2oj Ladder 4 some problems Ladder URL:http://a2oj.com/Ladder.jsp?ID=4难度等级:2问题提示: 1- 4A. Watermelon: ...
"Problem_C_Data.zip" 是一个压缩包文件,包含2020年美国数学建模竞赛(简称美赛)C题的题目及相应的原始数据。美赛是一项国际性的数学建模竞赛,每年吸引众多学生参与,旨在提升参赛者的数学、数据分析和解决实际...
Problem Arrangement zoj 3777
在操作系统课程中,"机器问题"(Machine Problem)通常指的是与计算机硬件、系统架构以及操作系统内核相关的复杂问题。这些问题涉及到资源管理、并发控制、进程调度、内存分配等多个核心概念,是理解操作系统工作...
算法设计里关于taxi problem的C语言代码
W ELCOME TO THE F IFTH EDITION OF C++ Programming: From Problem Analysis to Program Design. Designed for a first Computer Science (CS1) C++ course, this text provides a breath of fresh air to you and ...