题解:
简单的递推
n为偶--->n/2
n为奇---->n/2,n/2+1
代码:
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define LL long long #define CLR(x) memset(x,0,sizeof x) #define MC(x,y) memcpy(x,y,sizeof(x)) #define SZ(x) ((int)(x).size()) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 typedef pair<int,int> P; const double eps=1e-9; const int maxn=200100; const int mod=1e9+7; const int INF=1e9; LL x,y,n; LL DP(int m) { if(m==0) return 0; if(m==1) return x; if(m&1) return min(DP(m-1),DP(m+1))+x; return DP(m/2)+min(x*m/2,y); } int main() { cin>>n>>x>>y; cout<<DP(n)<<endl; }
时间: 2024-08-26 16:01:53