码迷,mamicode.com
首页 > 其他好文 > 详细

Educational Codeforces Round 16 E. Generate a String

时间:2016-10-09 00:18:57      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

题解:

简单的递推

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

标签:

原文地址:http://www.cnblogs.com/byene/p/5940453.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!