Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大废题

Posted by KatrineYang at 2016-07-01 00:07:29 on Problem 1163
//============================================================================
// Name        : main1163.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int mx(int a, int b){
	if(a < b) return b;
	return a;
}

int main() {
	int triangle[101][101];
	int ceng;
	cin >> ceng;
	for(int i = 1; i <= ceng; i++){
		for(int j = 0; j < i; j++){
			cin >> triangle[i-1][j];
		}
	}
	int res[101][101];
	for(int i = 0; i < ceng; i++){
		res[ceng-1][i] = triangle[ceng-1][i];
	}
	for(int i = ceng-2; i >= 0; i--){
		for(int j = 0; j <= i; j++){
			res[i][j] = triangle[i][j] + mx(res[i+1][j], res[i+1][j+1]);
		}
	}
	cout << res[0][0] << endl;
	//cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator