Assignment 10 122CS0560
Assignment 10 122CS0560
ROLL- 122CS0560
ASSIGNMENT - 10
int main() {
int n;
cout << "Enter the number of items: ";
cin >> n;
vector<int> value(n);
vector<int> weight(n);
int W;
cout << "Enter the capacity of the knapsack: ";
cin >> W;
return 0;
}
if (i == 0 || C == 0) {
return 0;
}
if (w[i - 1] > C) {
return KS(v, w, C, i - 1);
}
else {
return max(v[i - 1] + KS(v, w, C - w[i - 1], i - 1), KS(v, w, C, i - 1));
}
}
int main() {
int N, C;
cout << "Enter the number of items: ";
cin >> N;
vector<int> v(N);
vector<int> w(N);
cout << "Enter the values of items: ";
for (int i = 0; i < N; ++i) {
cin >> v[i];
}
cout << "Maximum value subset: " << KS(v, w, C, N) << endl;
return 0;
}
if (i == 0 || C == 0) {
return 0;
}
if (w[i - 1] > C) {
return KS(v, w, C, i - 1);
}
else {
return max(v[i - 1] + KS(v, w, C - w[i - 1], i - 1), KS(v, w, C, i - 1));
}
}
int main() {
int N, C;
cout << "Enter the number of items: ";
cin >> N;
vector<int> v(N);
vector<int> w(N);
cout << "Maximum value subset: " << KS(v, w, C, N) << endl;
return 0;
}
Q2. Matrix Chain Multiplication
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cout << "Enter the number of dimentions: ";
cin >> n;
vector<int> dims(n);
cout << "Enter values for each dimention: ";
for (int i = 0; i < n; ++i)
cin >> dims[i];
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cout << "Enter the number of dimentions: ";
cin >> n;
vector<int> dims(n);
cout << "Enter values for each dimention: ";
for (int i = 0; i < n; ++i)
cin >> dims[i];
return 0;
}
Q3. Convex Polygon Triangulation
#include <bits/stdc++.h>
using namespace std;
//RECURSIVE
double minPerimeterRecWrapper(const vector<pair<int, int>>& poly) {
return minPerimeterRec(poly, 0, poly.size() - 1);
}
// Dynamic Programming
double minPerimeterDP(const vector<pair<int, int>>& poly) {
int n = poly.size();
vector<vector<double>> dp(n, vector<double>(n, 0));
return 0;
}
Q4 . Reduction of MCM to polygon triangulation
#include<bits/stdc++.h>
using namespace std;
// Recursive
double minPerimeterRec(const vector<pair<int, int>>& poly, int i, int j) {
if (j - i < 2)
return 0;
// Dynamic Programming
double minPerimeterDP(const vector<pair<int, int>>& poly) {
int n = poly.size();
vector<vector<double>> dp(n, vector<double>(n, 0));
int main() {
int n;
cout << "Enter the number of dimentions: ";
cin >> n;
vector<int> dims(n);
cout << "Enter values for each dimention: ";
for (int i = 0; i < n; ++i)
cin >> dims[i];
return 0;
}
Name - AASHISH KUMAR
ROLL- 122CS0560
ASSIGNMENT - 10
int main() {
string str1, str2;
cout << "Enter the first string: ";
cin >> str1;
cout << "Enter the second string: ";
cin >> str2;
int main() {
string str1, str2;
cout << "Enter the first string: ";
cin >> str1;
cout << "Enter the second string: ";
cin >> str2;
int main() {
string str1, str2;
cout << "Enter the first string: ";
cin >> str1;
cout << "Enter the second string: ";
cin >> str2;