[ACM] #POJ#1163

// http://poj.org/problem?id=1163
#include <iostream>
#include <stdlib.h> /*为了使用malloc*/

int No_1163(){	
	int rows = 0;		
	scanf("%d",&rows);   //输入三角形行数 rows
	
	int totalNumbs = (1+rows )*rows/2;  //计算三角形所包含的所有位置数		
	int *a =  (int*) malloc (totalNumbs*sizeof(int));
	
	//输入过程:从标准输入读入所有位置上的数值	
	int count = 0;
	for (int i = 1;i<=rows;i++){//i 表示第i行 
		for (int j= 1;j <= i;j++){ // j,每行读入j个数字; 
			scanf("%d",&(a[count]));
			count++;
		} 
	}
	
    //数据处理过程:从倒数第二行开始,计算每个位置与他下一行相邻两个位置数字和的最大值
	for (int i = rows-1; i>=1 ;i--){//i 表示第i行 ,从第1行到第n行 
		int startIndex = i*(i-1)/2;
		int nextStartIndex = (i+1)*i/2;
		for(int j = 0;j<i;j++){
			a[startIndex+j] += 
			a[nextStartIndex+j]>a[nextStartIndex+j+1] ? a[nextStartIndex+j]:a[nextStartIndex+j+1];
		} 
	}
	
	//输出过程:
	printf("%d",a[0]);
	free(a);
	return 0;
} 

int main(int argc, char** argv) {
	No_1163();
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值