Educational Codeforces Round 16 E. Generate a String
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 16 E. Generate a String相关的知识,希望对你有一定的参考价值。
题解:
简单的递推
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; }
以上是关于Educational Codeforces Round 16 E. Generate a String的主要内容,如果未能解决你的问题,请参考以下文章
Educational Codeforces Round 7 A
Educational Codeforces Round 7
Educational Codeforces Round 90
Educational Codeforces Round 33