BZOJ - 4428 记忆化搜索

BZOJ - 4428 记忆化搜索_第1张图片
BZOJ - 4428 记忆化搜索_第2张图片

#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
typedef long long int LL;
const LL INF = 1e18;
const int N = 1000005;
int n, r, p;
LL dp[N];

LL dfs(int n)
{
    if (dp[n])
        return dp[n];
    if (n <= 1)
        return 0;
    dp[n] = (LL)(n - 1) * p + r;
    for (int i = 2; i < n;) {
        dp[n] = min((LL)(i - 1) * p + dfs(ceil(n * 1.0 / i)) + r, dp[n]);
        i = ceil(n * 1.0 / (ceil(n * 1.0 / i) - 1));
    }
    return dp[n];
}

int main()
{
    //freopen("test.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    scanf("%d%d%d", &n, &r, &p);
    printf("%I64d\n", dfs(n));
    return 0;
}

你可能感兴趣的:(ACM-搜索)