tags:

views:

90

answers:

1

i have following dynamic problem we should have construct following triangle

             1
           2   3
          4  6  9
         8 12 18   27
        16 24 36 54  81
       32 48 72 108 162 243
      64 96 144 216 324 486 729

please can anybody help me to write algorithm for solve this problem?

A: 

Looking at the triangle, I see that the item at position i,0 has the value 2^i for all i >= 0. The value at position i,j is calculated by adding the values at positions i, j-1 and i-1, j-1 for all i>0, 0 < j <= i.

So to create the first n lines of the triangle just iterate i from 0 to n-1 and then j from 0 to i and fill in each value using the above rules.

sepp2k
To set this up as a dynamic programming problem, you need to initialize the "j"-line (`3^j`) as well.
Hamish Grubijan