-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ambujraj/master
Merging
- Loading branch information
Showing
310 changed files
with
13,664 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# HacktoberFest2018_chimdolin_come | ||
# HacktoberFest2018_chimdolin_come |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//0-1 Knapsack problem using dynamic programming | ||
#include<iostream.h> | ||
|
||
int max(int a, int b) { return (a > b)? a : b; } | ||
|
||
int knapSack(int W, int wt[], int val[], int n) | ||
{ | ||
int i, w; | ||
int K[n+1][W+1]; | ||
|
||
for (i = 0; i <= n; i++) | ||
{ | ||
for (w = 0; w <= W; w++) | ||
{ | ||
if (i==0 || w==0) | ||
K[i][w] = 0; | ||
else if (wt[i-1] <= w) | ||
K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]); | ||
else | ||
K[i][w] = K[i-1][w]; | ||
} | ||
} | ||
|
||
return K[n][W]; | ||
} | ||
|
||
void main() | ||
{ | ||
int val[] = {50, 110, 115}; | ||
int wt[] = {10, 20, 30}; | ||
int W = 50; | ||
int n = 1; | ||
int c=knapSack(W, wt, val, n); | ||
cout<<c; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" Knapsack problem by dynamic programming """ | ||
weight = [1,3,4,5] | ||
value = [1,4,5,7] | ||
n = len(weight)+1 | ||
max_wt = 7 | ||
v = [[0 for j in range(max_wt+1)] for i in range(n)] | ||
|
||
def print_items(i, j): | ||
if i>0 and j>0 : | ||
if v[i][j] != v[i-1][j] : | ||
print(str(weight[i-1])+"\t\t\t"+str(value[i-1])) | ||
print_items(i-1, v[i-1].index(v[i][j]-value[i-1])) | ||
else : | ||
print_items(i-1, j) | ||
|
||
|
||
def knapsack(): | ||
for i in range(1, n): | ||
for j in range(1, max_wt+1): | ||
if j-weight[i-1] >= 0 : | ||
v[i][j] = max([v[i-1][j], v[i-1][j-weight[i-1]]+value[i-1]]) | ||
else : | ||
v[i][j] = v[i-1][j] | ||
print("Selected Weight\t\tValue") | ||
print_items(n-1, max_wt) | ||
print("\nMaximum Value : "+str(v[n-1][max_wt])) | ||
|
||
knapsack() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
//chain matrix multiplication using recursion | ||
#include<iostream.h> | ||
|
||
int Order(int m[], int i, int j) | ||
{ | ||
if(i == j) | ||
return 0; | ||
int k; | ||
int min=0; | ||
int count; | ||
|
||
for (k = i; k <j; k++) | ||
{ | ||
count = Order(m, i, k) + | ||
Order(m, k+1, j) + | ||
m[i-1]*m[k]*m[j]; | ||
|
||
if (count < min) | ||
min = count; | ||
} | ||
|
||
return min; | ||
} | ||
|
||
|
||
void main() | ||
{ | ||
int arr[] = {1, 2, 3, 4, 5}; | ||
int n = 5; | ||
|
||
int c=Order(arr, 1, n-1)); | ||
cout<< "min no. of multiplications is: "<< c; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include<stdio.h> | ||
|
||
int main(){ | ||
int st1[8]={2,4,7,4,8,5,5,2},st2[8]={3,2,7,5,2,4,1,1},st3[8]={2,4,4,1,5,1,2,4},st4[8]={3,2,5,4,3,2,1,3}; | ||
int i,st1f,st2f,st3f,st4f; | ||
/* printf("Enter st1: "); | ||
for(i=0;i<8;i++) | ||
scanf("%d",&st3[i]); | ||
*/ | ||
printf("ST1 : "); | ||
for(i=0;i<8;i++){ | ||
printf("%d ",st1[i]); | ||
} | ||
printf("\nST2 : "); | ||
for(i=0;i<8;i++){ | ||
printf("%d ",st1[i]); | ||
} | ||
printf("\nST3 : "); | ||
for(i=0;i<8;i++){ | ||
printf("%d ",st1[i]); | ||
} | ||
printf("\nST4 : "); | ||
for(i=0;i<8;i++){ | ||
printf("%d ",st1[i]); | ||
} | ||
printf("\nEnter fitness functions of st1, st2, st3 and st4 : "); | ||
scanf("%d%d%d%d",&st1f,&st2f,&st3f,&st4f); | ||
printf("Fitness function :\n st1=%d\t st2=%d\t st3=%d\t st4=%d ",st1f,st2f,st3f,st4f); | ||
|
||
return 0; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.