UPC 攀登宝塔(基本状态转移)

博客探讨了UPC攀登宝塔问题,重点在于理解基本状态转移,包括从哪个跨度转移及主角的灵力状态。通过使用二维DP数组,区分灵力状态和步伐范围,来解决这一问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一个基本状态是每个台阶是以什么样的跨度转移过来的(一个格子之前还是两个格子之前),第二个基本状态就是主角本身是否处于灵力CD的状态。

所以对于DP数组需要开二维,一维记录灵力状态,另一维记录跨度范围。

//#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[50000], dp[2][20000];
int DETERMINATION()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    ll n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
    {
        dp[0][i] = INF;
        dp[1][i] = INF;//初始化
    }
    dp[0][0]=0,dp[0][1]=a[1],dp[1][1]=0;//起始状态
    for (int i = 2; i <= n; i++)
    {
        dp[0][i] = min(dp[0][i - 1] + a[i], dp[1][i - 1] + a[i]);//不使用灵力或者处于CD状态
        dp[1][i] = min(dp[0][i - 1], dp[0][i - 2]);//使用灵力
    }
    cout << min(dp[0][n], dp[1][n]) << endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值