当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。
The discrete wavelet transform is a popular tool for signal compression. In this problem, your job is to write a program to decompress a one-dimensional signal (a list of integers) that has been compressed by a simple wavelet transform.
To understand how this simple wavelet transform works, suppose that we have a list of an even number of integers. We compute the sum and difference of each pair of consecutive samples, resulting in two lists of sums and differences each having half the original length. Formally, if the original samples are
a(1),..., a(n)the i-th sum
s(i)
and difference d(i)
are computed as:for i = 1,...,n/2:This is then rearranged to give the transformed signal by first listing the sums and then the differences. For example, if the input signal is:
s(i) = a(2*i-1) + a(2*i)
d(i) = a(2*i-1) - a(2*i)
5, 2, 3, 2, 5, 7, 9, 6Then the sum and difference signals are:
s(i) = 7, 5, 12, 15Thus, the transformed signal is:
d(i) = 3, 1, -2, 3
7, 5, 12, 15, 3, 1, -2, 3
The same process is applied recursively to the first half of the transformed signal, treating s(i)
as the input signal, until the length of the input signal is 1. In the example above, the final transformed signal is:
39, -15, 2, -3, 3, 1, -2, 3It is assumed that the length of the original input is a power of 2, and the input signal consists of integers between 0 and 255 (inclusive) only.
8 39 -15 2 -3 3 1 -2 3 4 10 -4 -1 -1 0
5 2 3 2 5 7 9 6 1 2 3 4
时间上限 | 内存上限 |
5000 | 65536 |