UPC 抢金块(普通的状态转移)
此题的初始状态是1,终末状态位于n,而状态转移范围为s~t,所以对于每一状态,只需枚举其合法的转移方式并取最大值即可。
#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[5000],dp[5000];
int DETERMINATION()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
ll n;
cin >> n;
ll s, t;
cin >> s >> t;
for (int i = 1; i <= n; i++)
cin >> a[i];
dp[1] = a[1];
for (int i = s+1; i <= n; i++)
for (int j = s; j <= t; j++)
dp[i] = max(dp[i], dp[i - j] + a[i]);
//第二个for循环就是dp[i]=max(dp[i-s]+a[i],dp[i-s-1]+a[i],...,dp[i-t]+a[i])的另一个表现形式
cout << dp[n] << endl;
return 0;
}

浙公网安备 33010602011771号