dreamnyc

努力的去做一个普通人

Educational Codeforces Round 16 E 题 Generate a String

Generate a String
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

zscoder wants to generate an input file for some programming competition problem.

His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.

Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a' from the text file and y seconds to copy the contents of the entire text file, and duplicate it.

zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters 'a'. Help him to determine the amount of time needed to generate the input.

Input

The only line contains three integers nx and y (1 ≤ n ≤ 1071 ≤ x, y ≤ 109) — the number of letters 'a' in the input file and the parameters from the problem statement.

Output

Print the only integer t — the minimum amount of time needed to generate the input file.

Examples
input
8 1 1
output
4
input
8 1 10
output
8

     题意:输入一个数n,x,y  n表示生成字符的个数,每增加一个字符a需要x时间,是复制前面的串需要y时间。

   求生成n个字符a至少需要多长时间。

我们用dp[i]表示生成i个字符需要时间当i是偶数时,dp[i]=min(dp[i-1]+x,dp[i/2]+y)(增加或复制); 当i为奇数时,dp[i]=min(dp[i-1]+x,dp[(i+1)/2]+x+y)(增加或复制和删除)。



#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<vector>
#include<string.h>
#include<map>
#define INF 0x3f3f3f3f3f
using namespace std;
long long dp[10000009];

int main()
{
    int n;
    long long  x,y;
    scanf("%d%I64d%I64d",&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
            dp[i]=min(dp[i-1]+x,dp[i/2+1]+y+x);
    }
    printf("%I64d\n",dp[n]);


}










阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dreamNYC/article/details/52370593
文章标签: string codeforces
个人分类: 字符串 codeforces
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

Educational Codeforces Round 16 E 题 Generate a String

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭