码迷,mamicode.com
首页 > 其他好文 > 详细

USACO numtri 数塔问题

时间:2014-06-20 12:02:24      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:class   blog   code   2014   string   os   

/*
ID:kevin_s1
PROG:numtri
LANG:C++
*/

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <list>
#include <cmath>

using namespace std;
#define MAXN 1001

//gobal variable====
int R;
int tri[MAXN][MAXN];
int dp[MAXN][MAXN];
//==================
//dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j]) + tri[i][j]

//function==========

//==================

int main(){
	freopen("numtri.in","r",stdin);
	freopen("numtri.out","w",stdout);
	memset(dp,0,sizeof(dp));
	memset(tri,0,sizeof(tri));
	cin>>R;
	for(int i = 1; i <= R; i++){
		for(int j = 1; j <= i; j++){
			cin>>tri[i][j];
		}
	}
	dp[1][1] = tri[1][1];
	for(int i = 1; i <= R; i++){
		for(int j = 1; j <= i; j++){
			dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j]) + tri[i][j];
		}
	}
	int maxnum = 0;
	for(int i = 1; i <= R; i++){
		if(dp[R][i] > maxnum )
			maxnum = dp[R][i];
	}
	cout<<maxnum<<endl;
	
	return 0;
}

USACO numtri 数塔问题,布布扣,bubuko.com

USACO numtri 数塔问题

标签:class   blog   code   2014   string   os   

原文地址:http://blog.csdn.net/kevin_samuel/article/details/28510483

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!