GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Find number of times a string occurs as a sub-sequence in given string.Kindly explain the solution using Dynamic Programming.

Though the solution is available on geeks for geeks(http://www.geeksforgeeks.org/find-number-times-string-occurs-given-string/) but I cannot understand the DP approach. Kindly explain the DP approach in detail.

Heres my java code for the brute force approach.

public class Temp1 {
    static int count = 0;
    static void rec(String a, String b){
        if (b.length()==0){
            count++;
            return;
        }
        for (int i = 0; i<a.length();i++){
            if (a.charAt(i)==b.charAt(0))
                rec(a.substring(i+1),b.substring(1));
        }
    }

    public static void main(String[] args)throws IOException{
        BufferedReader ob = new BufferedReader(new InputStreamReader(System.in));
        rec(ob.readLine(),ob.readLine());
        System.out.println(count);
    }
}

Thanks.

asked Aug 31, 2016 by shaurya_j
...