其他分享
首页 > 其他分享> > poj 1163(简单dp)

poj 1163(简单dp)

作者:互联网

#include<iostream>
#include<string.h>
#include<string>
#include<sstream>
#include<vector>
#include<deque>
#include<map>
#include<algorithm>
#include<iomanip>
#include<math.h>
#include<set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int in[100][100];
int n;
int dp[100][100];
/*递归超时
int dp(int i, int j)
{
	if (in[i][j] == -1)
		return 0;
	int left = in[i][j] + dp(i+1,j);
	int right = in[i][j] + dp(i + 1, j + 1);
	return left > right ? left : right;
}
*/
int main()
{
	while (cin >> n)
	{
		memset(in, -1, sizeof(in));
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j <= i; j++)
			{
				cin >> in[i][j];
			}
		}
		for (int i = 0; i < n; i++)
			dp[n - 1][i] = in[n - 1][i];
		for (int i = n - 2; i >= 0; i--)
		{
			for (int j = 0; j <= i; j++)
				dp[i][j] = in[i][j] + max(dp[i + 1][j], dp[i + 1][j + 1]);
		}
		cout << dp[0][0]<< endl;
	}
	return 0;
}

标签:right,1163,int,long,poj,100,include,dp
来源: https://www.cnblogs.com/QingFengDaHui/p/10440089.html