数塔(状态转移方程的概念)

动态规划的核心是状态转移方程,状态指事物在特定位置的属性,如数值或特性。状态转移则是其他状态通过特定方式影响当前状态。以楼梯问题为例,从不同台阶到达当前位置即为状态转移。在寻找最大路线问题中,从下至上或从上至下,利用加法交换律,可从两个相邻状态选择最优解。

动态规划的核心往往是一个状态转移方程,而何谓状态呢?就是对于某特定事物在某一个位置时具有的属性,比如所携带的数值或者是其他的一些特性。状态转移又是什么呢?就是与当前状态相关的若干的状态通过某种特定方式转移到了当前状态上,在这期间所携带的特性可能发生了一些改变。比如说一个楼梯,我可以从两个台阶前迈过来,也可以从一个台阶前走过来,这都是状态转移的一种。

同样的,在这个题里,既然是要求一条和最大的路线,那么根据加法交换律,从下到上走和从上到下走是一样的效果。所以对于每一i层的元素,总有第i+1层的两个点可以与之连接,如果

#include<pch.h>
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <cstring>
#include <cmath>
#define DETERMINATION main
#define lldin(a) scanf_s("%lld", &a)
#define println(a) printf("%lld\n", a)
#define reset(a, b) memset(a, b, sizeof(a))
const int INF = 0x3f3f3f3f;
using namespace std;
const double PI = acos(-1);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int mod = 1000000007;
const int tool_const = 19991126;
const int tool_const2 = 2000;
inline ll lldcin()
{
	ll tmp = 0, si = 1;
	char c;
	c = getchar();
	while (c > '9' || c < '0')
	{
		if (c == '-')
			si = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9')
	{
		tmp = tmp * 10 + c - '0';
		c = getchar();
	}
	return si * tmp;
}
///Untersee Boot IXD2(1942)
/**Although there will be many obstructs ahead,
the desire for victory still fills you with determination..**/
/**Last Remote**/
ll a[500][500];
int DETERMINATION()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	ll n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= i; j++)
			cin >> a[i][j];
	for (int i = n - 1; i >= 1; i--)
		for (int j = 1; j <= i; j++)
			a[i][j] = a[i][j] + max(a[i+1][j], a[i+1][j + 1]);//状态转移方程
	cout << a[1][1] << endl;
	return 0;
}

需要得到最优答案,一直从这两个状态中选择一个最优状态即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值