Consider n (decimal) digits a1, . , an (i., ai {0, 1, . , 9}) and an integer x with 9n x 9n. An x-signing consists of n values s1, .

Consider n (decimal) digits a1, . . . , an (i.e., ai ∈ {0, 1, . . . , 9}) and an integer x with −9n ≤ x ≤ 9n. An x-signing consists of n values s1, . . . , sn with si ∈ {1, 0, −1} such that sum i=1 to n (si· ai) = x.Your goal in this task is to devise a dynamic-programming algorithm that given a1, . . . , an and x, decides whether there is an x-signing and, if so, outputs it. To that end,

• define an appropriate table,

• derive a recurrence,

• show how to efficiently fill the table, and

• devise a way to reconstruct the signing (if existent) from the filled table.

Analyze the running time of your algorithm

Leave a Reply