3302. 打印

lnu_cxn

int main() {
int n, x, y;
cin >> n >> x >> y;
vector s(n + 1, 0);
s[1] = x;
for (int i = 2; i < n + 1; i++) {
if (i % 2 == 0) {
s[i] = min(s[i - 1] + x, s[i / 2] + y);
}
else {
s[i] = min(s[i - 1] + x, s[(i + 1) / 2] + y + x);
}
}
cout << s[n] << endl;
return 0;
}

Andrew-Malcom

include

using namespace std;
long int dp[10000010];
int main()
{
        int n,x,y;
        cin>>n>>x>>y;
        dp[0]=0,dp[1]=x;
        for(int i=2;i<=n;i++){
                if(i%2==0){
                        dp[i]=min(dp[i-1]+x,dp[i/2]+y);
                }
                else if(i%2!=0){
                        dp[i]=min(min(dp[i-1]+x,dp[i/2]+x+y),dp[(i+1)/2]+x+y);
                }
        }
        cout<<dp[n];
}
cd106224
//state:dp[i] 表示总数为i时所需的最小时间
#include <iostream>
#include <algorithm>
using namespace std;
using LL = long long;

LL dp[10000002];
int n, x, y;

int main() {
    fill(dp, dp + 10000002, 0);
    cin >> n >> x >> y;
    dp[1] = x;
    for (int i = 2; i < 10000002; ++i) {
        if (i & 1) {
            dp[i] = min(min(dp[i - 1] + x, dp[i >> 1] + y + x), dp[(i + 1) >> 1] + y + x);
        }
        else {
            dp[i] = min(dp[i - 1] + x, dp[(i + 1)>> 1] + y);
        }
    }
    cout << dp[n] << endl;
    return 0;
}
你当前正在回复 博客/题目
存在问题!