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
//We can think of recursive solution as we did with Knapsack and build Memoized and Tabulation approach from there | |
#include<bits/stdc++.h> | |
using namespace std; | |
void initializeLcs(int **lcs, int val,int n, int m){ | |
for(int i=0;i<=n;i++){ | |
for(int j=0;j<=m;j++){ | |
lcs[i][j] = val; | |
} |
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
#include<bits/stdc++.h> | |
using namespace std; | |
void print2dVector(vector< vector<int> > v){ | |
int x = v.size(); | |
int y = v[0].size(); | |
for(int i=0;i<x;i++){ | |
for(int j=0;j<y;j++){ | |
cout << v[i][j] << " "; | |
} |
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
/* | |
Mr. Kim has to deliver refrigerators to N customers. From the office, he is going to visit all the customers and then return to his home. Each location of the office, his home, and the customers is given in the form of integer coordinates (x,y) (0≤x≤100, 0≤y≤100) . The distance between two arbitrary locations (x1, y1) and (x2, y2) is computed by |x1-x2| + |y1-y2|, where |x| denotes the absolute value of x; for instance, |3|=|-3|=3. The locations of the office, his home, and the customers are all distinct. You should plan an optimal way to visit all the N customers and return to his among all the possibilities. | |
You are given the locations of the office, Mr. Kim’s home, and the customers; the number of the customers is in the range of 5 to 10. Write a program that, starting at the office, finds a (the) shortest path visiting all the customers and returning to his home. Your program only have to report the distance of a (the) shortest path. | |
Constraints | |
5≤N≤10. Each location (x,y) is in a bounded grid, 0≤x≤1 |
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
/* | |
You’ll be given a grid as below: | |
0 1 0 2 0 --> Non highlighted part | |
0 2 2 2 1 | |
0 2 1 1 1 | |
1 0 1 0 0 | |
0 0 1 2 2 | |
1 1 0 0 1 | |
x x S x x -->highlighted yellow |
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
#include<iostream> | |
using namespace std; | |
int n; | |
int arr[100][100]={0}; | |
bool isBiPartite(int i,int color[]){ | |
bool flag = true; | |
for(int j=0;j<n;j++){ | |
if(arr[i][j] == 1){ | |
if(color[j] == -1){//If color of current node not set |
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
#include<iostream> | |
using namespace std; | |
int findLeft(int arr[],int n,int j,bool isBurst[],bool &found){//To find next left balloon that is not burst | |
if(j <= 0){ | |
found = false; | |
return 1; | |
} | |
for(int i=j-1;i>=0;i--){ | |
if(!isBurst[i]){ |
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
#include<iostream> | |
using namespace std; | |
#define i_max 2147483647 | |
int nw,sx,sy,dx,dy;//Source and destination co-ordinates | |
int dist[1001][1001]; | |
bool set[1001][1001]; | |
class Wormhole{ | |
public: | |
int x1,y1,x2,y2,cost; | |
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
#include<bits/stdc++.h> | |
using namespace std; | |
class MaxHeap{ | |
private: | |
//Variables | |
vector<int> v; | |
int size; | |
//Properties |