The Triangle
时间限制:
1000 ms | 内存限制:
65535 KB
难度:
4
-
描述
-
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
(Figure 1)
Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right.-
输入
- Your program is to read from standard input. The first line contains one integer N: the number of rows in the triangle. The following N lines describe the data of the triangle. The number of rows in the triangle is > 1 but <= 100. The numbers in the triangle, all integers, are between 0 and 99. 输出
- Your program is to write to standard output. The highest sum is written as an integer. 样例输入
-
5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5
样例输出
-
30
上传者
-
聪明的“KK”
非洲某国展馆的设计灵感源于富有传奇色彩的沙漠中陡然起伏的沙丘,体现出本国不断变换和绚丽多彩的自然风光与城市风貌。展馆由五部分组成,馆内影院播放名为《一眨眼的瞬间》的宽银幕短片,反映了建国以来人民生活水平和城市居住环境的惊人巨变。
可移动“沙丘”变戏法 的灵感源于其独特而雄伟的自然景观——富于传奇色彩的险峻沙丘。宏伟的结构、可循环的建材,与大自然相得益彰。环绕一周,发现它正是从沙丘那不断变换的形态中汲取灵感的。外形逼真到无论从哪个角度去观察,都能清楚地辨识出沙丘的特征。
它“坡面”高达20米,微风吹来,你是否感觉到沙的流动?用手去触碰,却发现原来是“魔术戏法”。它表面的不锈钢面板呈现出一种富于变幻的色彩,从不同角度观察,呈现不同色泽,由此来模仿流动沙丘的光感。
走进第三展厅有一个超大的屏幕,通过奇妙的特效,让观众犹如亲身来到浩瀚的沙漠。更为奇妙的是,只见一个小动物“KK”正从沙漠区域(矩形)的左上角沿着向右或向下的方向往右下角跑去。KK太聪明了,它居然能在跑的过程中会选择吃掉尽可能多的虫子线路。
你知道它吃掉多少虫子吗?-
输入
-
第一行:N M (1≤N M≤20 0≤Xij≤500(i=1,2„.N, j=1,2„,M)
)表示沙漠是一个N*M的矩形区域
接下来有N行:每行有M个正整数,Xi1 Xi2 ……Xim 表示各位置中的虫子数(单个空格隔开)
假设“KK”只能向右走或向下走。
输出
- 输出有一个整数, 表示“KK”吃掉最多的虫子数。 样例输入
-
3 4 3 1 2 8 5 3 4 6 1 0 2 3
样例输出
-
24
来源
- 第三届河南省程序设计大赛 上传者
- 苗栋栋
-
第一行:N M (1≤N M≤20 0≤Xij≤500(i=1,2„.N, j=1,2„,M)
hdu2084 数塔 一样
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int m=sc.nextInt(); int[][]f=new int[m+1][m+1]; int c=0,i,j = 1; for( i=1;i<=m;i++) for( j=1;j<=i;j++) f[i][j]=sc.nextInt(); for( i=m-1;i>=1;i--) for( j=1;j<=i;j++) f[i][j]=f[i][j]+Math.max(f[i+1][j], f[i+1][j+1]); System.out.println(f[1][1]); } } }
聪明的kk
时间限制: 1000 ms | 内存限制: 65535 KB难度: 3-
描述
import java.util.Scanner; public class nyoj_171河南省第三届程序设计大赛 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); int m=sc.nextInt(); int[][]f=new int[n+1][m+2]; int i,j ,c; for( i=1;i<=n;i++) for( j=1;j<=m;j++){ c=sc.nextInt(); f[i][j]=c+Math.max(f[i][j-1], f[i-1][j]); } System.out.println(f[n][m]);//最终的最多者 } } }