CF717B.R3D3’s Summer Adventure

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The White Buttons" and their hit song "Dacan the Baker", he met another robot for whom he was sure is the love of his life. Well, his summer, at least. Anyway, R3D3 was too shy to approach his potential soulmate, so he decided to write her a love letter. However, he stumbled upon a problem. Due to a terrorist threat, the Intergalactic Space Police was monitoring all letters sent in the area. Thus, R3D3 decided to invent his own alphabet, for which he was sure his love would be able to decipher.

There are n letters in R3D3’s alphabet, and he wants to represent each letter as a sequence of '0' and '1', so that no letter’s sequence is a prefix of another letter's sequence. Since the Intergalactic Space Communications Service has lately introduced a tax for invented alphabets, R3D3 must pay a certain amount of money for each bit in his alphabet’s code (check the sample test for clarifications). He is too lovestruck to think clearly, so he asked you for help.

Given the costs _c_0 and _c_1 for each '0' and '1' in R3D3’s alphabet, respectively, you should come up with a coding for the alphabet (with properties as above) with minimum total cost.

R3D3 在 MDCS 公司实习了一段时间。在挣够了钱之后,他决定去一个遥远、遥远的地方度假。他喜欢日光浴、喝无酒精鸡尾酒,以及去听当地流行乐队的演唱会。在聆听“The White Buttons”乐队及其热门歌曲《Dacan the Baker》时,他遇到了另一个机器人——他确信,这便是自己此生挚爱(至少是这个夏天的挚爱)。然而,R3D3 太害羞,不敢主动接近这位潜在的意中人,于是决定给她写一封情书。但这时他遇到了一个问题:由于存在恐怖主义威胁,星际空间警察正在监控该区域内所有寄出的信件。因此,R3D3 决定发明一套属于自己的字母表,并确信他的心上人一定能够破译。

R3D3 的字母表中共有 nn 个字母,他希望将每个字母表示为一段由字符 '0' 和 '1' 组成的序列,使得任意一个字母的编码序列均不为另一个字母编码序列的前缀(即满足前缀码性质)。由于星际空间通信服务最近对自创字母表征收税费,R3D3 必须为其字母表编码中的每一位支付一定费用(参见样例测试以进一步明确规则)。而此时的 R3D3 已被爱情冲昏头脑,无法清晰思考,因此请求你的帮助。

给定字母表中每个 '0' 和 '1' 所对应的费用 c0c_0 和 c1c_1,你需要设计一种满足上述性质的编码方案,使得整个字母表编码的总费用最小。

输入格式

The first line of input contains three integers n (2 ≤ n ≤ 108), _c_0 and _c_1 (0 ≤ _c_0, _c_1 ≤ 108) — the number of letters in the alphabet, and costs of '0' and '1', respectively.

输入的第一行包含三个整数 nn(2≤n≤1082 \leq n \leq 10^8)、c0c_0 和 c1c_1(0≤c0,c1≤1080 \leq c_0, c_1 \leq 10^8)——分别表示字母表中的字母个数,以及字符 '0' 和 '1' 的代价。

输出格式

Output a single integer — minimum possible total a cost of the whole alphabet.

输出一个整数——整个字母表的最小可能总成本。

输入输出样例

  • 输入#1

    4 1 2

    输出#1

    12

说明/提示

There are 4 letters in the alphabet. The optimal encoding is "00", "01", "10", "11". There are 4 zeroes and 4 ones used, so the total cost is 4·1 + 4·2 = 12.

字母表中有 4 个字母。最优编码为 “00”、“01”、“10”、“11”。共使用了 4 个 0 和 4 个 1,因此总代价为 4⋅1 + 4⋅2 = 124·1 + 4·2 = 12。

输入解题思路,AI测评打分。不知道怎么写?

首页