Showing posts with label Dynamic Programming. Show all posts
Showing posts with label Dynamic Programming. Show all posts

Sunday, June 28, 2015

C Code for Longest Common Subsequence Using Dynamic Programming

Here's the C Code for LCS using Dynamic programming :-


Output:-
Output:-

Matrix Generated

0 |0 |0 |0 |0 |
0 |0 |0 |0 |0 |
0 |1 |1 |1 |1 |
0 |1 |2 |2 |2 |
0 |1 |2 |3 |3 |
0 |1 |2 |3 |4 |

Length of Longest Common Subsequence = 4

Continue Reading →

Saturday, June 27, 2015

C Code for Knapsack Problem using Dynamic Programming

Knapsack problem
Knapsack problem (Photo credit: Wikipedia)
Knapsack Problem using Dynamic Programming.

Code:-


Sample Output:- 

Enter the number of elements : 3
Enter the profit and weights of the elements
Item no : 1
4 6
Item no : 2
1 2
Item no : 3
7 3
Enter the capacity
7
Items in the KnapSack are :
Sl.no    weight          profit
----------------------------------------
1        2                1
2        3                7
Total profit = 8
Continue Reading →

Follow Me!

Followers

Visitor Map