Calculate g(1000) given the following definition of g function..

+1 vote
g(1) = g(2) = .. g(10) = 1

g(n) = g(n-1) + 3 *g(n-3) + 7*g(n-10)
asked Jun 8 in Dynamic Programming by Amrinder Arora (38 points)
recategorized Jun 16 by Amrinder Arora

1 Answer

0 votes
Use this as a hint..

package edu.gwu.cs6212;
import java.math.BigDecimal;

public class Fib {
    public static void main(String[] args) {
        BigDecimal[] fibNums = new BigDecimal[1000];
        fibNums[0] = BigDecimal.ONE;
        fibNums[1] = BigDecimal.ONE;
        for (int i = 2; i < 1000; i++) {
            fibNums[i] = fibNums[i - 1].add(fibNums[i - 2]);
        }
        for (int i = 5; i < 1000; i += 5) {
            System.out.println(i + ": " + fibNums[i - 1]);
        }
    }
}
answered Jun 8 by Amrinder Arora (38 points)
The Book: Analysis and Design of Algorithms | Presentations on Slideshare | Lecture Notes, etc
...