CF132E.Bits of merry old England
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Another feature of Shakespeare language is that the variables are named after characters of plays by Shakespeare, and all operations on them (value assignment, output etc.) look like a dialog with other characters. New values of variables are defined in a rather lengthy way, so a programmer should try to minimize their usage.
You have to print the given sequence of n integers. To do this, you have m variables and two types of operations on them:
- variable=integer
- print(variable)
Any of the m variables can be used as variable. Variables are denoted by lowercase letters between "a" and "z", inclusive. Any integer number can be used as integer.
Let's say that the penalty for using first type of operations equals to the number of set bits in the number integer. There is no penalty on using second type of operations. Find and output the program which minimizes the penalty for printing the given sequence of numbers.
莎士比亚编程语言的另一特点是:变量以莎士比亚戏剧中的人物命名,所有对变量的操作(如赋值、输出等)均以与其他角色对话的形式呈现。变量新值的定义方式较为冗长,因此程序员应尽量减少其使用次数。
你需要输出给定的长度为 n 的整数序列。为此,你拥有 m 个变量,以及两类操作:
variable = integerprint(variable)
上述 m 个变量中的任意一个均可作为 variable 使用。变量用小写字母表示,取值范围为 "a" 到 "z"(含端点)。integer 可为任意整数。
我们规定:第一类操作(即赋值操作)的“惩罚值”等于整数 integer 的二进制表示中 1 的个数(即 popcount 或汉明重量);第二类操作(即 print 操作)不产生任何惩罚值。请找出并输出一个能以最小惩罚值打印给定整数序列的程序。
输入格式
The first line of input contains integers n and m (1 ≤ n ≤ 250, 1 ≤ m ≤ 26). The second line contains the sequence to be printed. Each element of the sequence is an integer between 1 and 109, inclusive. The sequence has to be printed in the given order (from left to right).
输入的第一行包含整数 n 和 m(1 ≤ n ≤ 250,1 ≤ m ≤ 26)。第二行包含待打印的序列。序列中每个元素均为介于 1 到 109(含)之间的整数。该序列需按给定顺序(从左到右)打印。
输出格式
Output the number of lines in the optimal program and the optimal penalty. Next, output the program itself, one command per line. If there are several programs with minimal penalty, output any of them (you have only to minimize the penalty).
输出最优程序的行数及最优罚值。接下来,输出该程序本身,每行一条指令。若存在多个罚值最小的程序,输出其中任意一个(你只需使罚值最小即可)。
输入输出样例
输入#1
7 2 1 2 2 4 2 1 2
输出#1
11 4 b=1 print(b) a=2 print(a) print(a) b=4 print(b) print(a) b=1 print(b) print(a)
输入#2
6 3 1 2 3 1 2 3
输出#2
9 4 c=1 print(c) b=2 print(b) a=3 print(a) print(c) print(b) print(a)
输入解题思路,AI测评打分。不知道怎么写?