|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|10 초||128 MB||21||5||5||33.333%|
The term “Harvard architecture” applies to a computer that has physically separate memories for instructions and data. The term originated with the Harvard Mark I computer, delivered by IBM in 1944, which used paper tape for instructions and relays for data.
Some modern microcontrollers use the Harvard architecture – but not paper tape and relays! Data memory is organized in banks, each containing the same number of data items. Each data-referencing instruction has a byte offset f to a bank, and a bit a that is used to select the bank to be referenced. If a is 0, then bank 0 is referenced. If a is 1, then the value in a bank select register (BSR) identiﬁes the bank to be used. Assume each instruction takes the same time to execute, and there is an instruction that can set the BSR’s value.
For example, suppose there are 4 banks of 8 bytes each. To access location 5, either use a single instruction with a = 0 and f = 5, or set the BSR to 0 in one instruction and then use an instruction with a = 1 and f = 5. The ﬁrst approach is faster since it does not require setting the BSR.
Now suppose (with the same memory) the location to access is 20. Only one approach will work here: execute an instruction that sets the BSR to 2 (unless the BSR already has the value 2) and then use an instruction with a = 1 and f = 4.
A program is a sequence of operations. Each operation is either
Your problem is to determine the minimum running time of programs. In particular, given the number and size of the memory banks and a program to be executed, ﬁnd the minimum number of instructions (which reference memory location and possibly set the BSR) that must be executed to run the program. To do this you must identify a mapping of variables to memory banks that yields the smallest execution time, and report that execution time – that is, the number of memory references and BSR register settings required. The BSR’s value is initially undeﬁned, and changes only when an instruction explicitly sets its value.
The input consists of a single test case. A test case consists of two lines. The ﬁrst line contains two integers b and s, where 1 ≤ b ≤ 13 is the number of memory banks and 1 ≤ s ≤ 13 is the number of variables that can be stored in each memory bank. The second line contains a non-empty program with at most 1 000 space-separated elements (each Rn, Vi, and E counts as one element).
You may assume the following:
Display the minimum number of instructions that must be executed to complete the program.
1 2 V1 V2 V1 V1 V2