A8303 | Bits of merry old England
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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 $10^{9}$ , inclusive. The sequence has to be printed in the given order (from left to right).
输出格式
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)
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted