luogu P2134 百日旅行
题目链接
题解
dp方程好想吧
优化有些玄学惹 不会证....
不过我会三分和贪心 \滑稽
但还是写dp吧
代码
#include<cstdio>
#include<cstring>
#include<algorithm>
inline int read() {
int x = 0,f = 1;char c = getchar();
while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
while(c <= '9' && c >= '0') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int maxn = 200007;
int q , p , g;
int n;
int dp[maxn][2];
int main () {
n = read(), p = read(), q = read();
for(int i = 1;i <= n;++ i) {
for(int j = g + 1;j < i;++ j)
if(dp[g][1] + (i - g) * (i - g) * p > dp[j][1] + (i - j) * (i - j) * p)
g = j;
dp[i][1] = std::min (dp[i - 1][1],dp[i - 1][0]) + q;
dp[i][0] = dp[g][1] + (i - g) * (i - g) * p;
}
printf("%d\n",std::min(dp[n][0],dp[n][1]));
return 0;
}