View Code of Problem 4063

#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
const int N = 1010;
int a[N][N], ans, n, dp[N][N];
int main() {
	while (cin >> n) {

		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= i; j++)
				cin >> a[i][j];

		for (int j = 1; j <= n; j++)
			dp[n][j] =a[n][j];
		for(int i=n-1;i>=1;i--)
			for(int j=1;j<=i;j++)
				dp[i][j]=min(dp[i+1][j],dp[i+1][j+1])+a[i][j];


		cout<<dp[1][1];
	}
}

Double click to view unformatted code.


Back to problem 4063