dp[i]表示修复i个bug所需要的最小时间,修复第i个bug,要么是单独修第i个,要么是和第i - 1,i - 2.....1个一起修,那么状态转移方程dp[i] = min(dp[i],arr[i] + pow4[i - j + 1] + dp[j - 1]);其中j从i - 1开始枚举,但是这样枚举会超时。可以发现题目的修复时间为x的四次方,同时修复的个数一定不能很多,那么最多是多少呢,发现22的四次方是大于2e5的,如果选择大于22个,肯定不如单独修一个,所以个数从1枚举到22即可
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<math.h>
#include<set>
#include<functional>
using namespace std;
#define int long long
using ull = unsigned long long;
inline int inc(int x,int v,int mod){x+=v;return x>=mod?x-mod:x;}//代替取模+
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N = 2e5 + 10,M = log2(N)+1;;
const int mod = 1e9 + 7;
inline int read()
{
int x = 0,f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
x = x * 10 + ch - '0',ch = getchar();
return x * f;
}
void solve()
{
int n,m;
cin >> n >> m;
vector<int>arr(m + 10);
vector<int>pow(30);
for(int i = 1; i <= m ; i ++)
{
cin >> arr[i];
}
for(int i = 1; i <= 25; i ++)
{
pow[i] = i * i * i * i;
}
vector<int>dp(m + 10,0x3f3f3f3f3f3f3f3f);
dp[0] = 0;
dp[1] = arr[1] + 1;
for(int i = 2; i <= m; i ++)
{
dp[i] = arr[i] + 1 + dp[i - 1];
for(int j = i - 1; i - j + 1 <= 25; j --)
{
if(j - 1 < 0) break;
dp[i] = min(dp[i],arr[i] + pow[i - j + 1] + dp[j - 1]);
}
//cout << dp[i] << ' ';
}
cout << dp[m] << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int tt = 1;
//cin >> tt;
while(tt --)
{
solve();
}
}