会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
SDJL的足迹
首页
博问
闪存
管理
USACO_1_5_Number Triangles
非常简单的动态规划,不说了~~~
Code
/**/
/*
ID: sdjllyh1
PROG: numtri
LANG: JAVA
complete date: 2008/11/23
author: LiuYongHui From GuiZhou University Of China
more article: www.cnblogs.com/sdjls
*/
import
java.io.
*
;
import
java.util.
*
;
public
class
numtri
{
private
static
int
n;
private
static
int
[][] values
=
new
int
[
1002
][
1002
];
private
static
int
[][] highest
=
new
int
[
1002
][
1002
];
private
static
int
highestSum
=
0
;
public
static
void
main(String[] args)
throws
IOException
{
init();
run();
output();
System.exit(
0
);
}
private
static
void
run()
{
highest[
1
][
1
]
=
values[
1
][
1
];
for
(
int
i
=
2
; i
<=
n; i
++
)
for
(
int
j
=
1
; j
<=
i; j
++
)
{
highest[i][j]
=
Math.max(highest[i
-
1
][j], highest[i
-
1
][j
-
1
])
+
values[i][j];
}
for
(
int
j
=
1
; j
<=
n; j
++
)
{
highestSum
=
Math.max(highestSum, highest[n][j]);
}
}
private
static
void
init()
throws
IOException
{
BufferedReader f
=
new
BufferedReader(
new
FileReader(
"
numtri.in
"
));
n
=
Integer.parseInt(f.readLine());
for
(
int
i
=
1
; i
<=
n; i
++
)
{
StringTokenizer st
=
new
StringTokenizer(f.readLine());
for
(
int
j
=
1
; j
<=
i; j
++
)
{
values[i][j]
=
Integer.parseInt(st.nextToken());
}
}
f.close();
}
private
static
void
output()
throws
IOException
{
PrintWriter out
=
new
PrintWriter(
new
BufferedWriter(
new
FileWriter(
"
numtri.out
"
)));
out.println(highestSum);
out.close();
}
}
posted on
2008-11-23 15:16
刘永辉
阅读(
238
) 评论(
0
)
收藏
举报
刷新页面
返回顶部