This file contains hidden or 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
/* | |
Ncr using pascal triangle | |
@author: rohit | |
pretty dynamic programming approach | |
space complexity:-0(n^2) | |
time complexity:-0(1) | |
in make_pascal_2() | |
space complexity :- 0(k) | |
time complexity :- o(n*k) |
This file contains hidden or 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
/* | |
finding power of a^b mod M | |
@author : rohit | |
functions :- | |
1)power():- | |
rule:- x^n= (x^2)^(n/2) if(n is even) | |
x^n= x* (x^2)^(n-1/2) if(n is odd) | |
space complexity:- O(1) | |
time complexity :- O(n) |
This file contains hidden or 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
/* | |
test[i][j] means to find number of ways it can be done | |
classy problem | |
*/ | |
#include <stdio.h> | |
#include <iostream> | |
#define M 10 | |
using namespace std; |
This file contains hidden or 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
/* | |
bit mask operations:- | |
1)shift left :- x<<1 | |
2)shift right:- x>>1 | |
3)and :- x&1 | |
4)x|1 :- x|1 | |
5)~x :- not x(flip every bit) | |
advanced bit mask operations:- |
This file contains hidden or 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
/* | |
Coin change problem (classical dynamic programming problem) | |
@author : rohit | |
*/ | |
#include <iostream> | |
#include <stdio.h> | |
#include <vector> | |
#define INF 1e9 |
This file contains hidden or 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
/* | |
to find longest non decreasing subsequence (another classical dp problem) | |
@author:rohit | |
*/ | |
#include <iostream> | |
#include <stdio.h> | |
#include <vector> | |
#define MAX 10001 |
This file contains hidden or 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
/* | |
maximum sub sequence in an array(dp solution) | |
@author:rohit | |
*/ | |
#include <iostream> | |
#include <stdio.h> | |
#include <vector> |
This file contains hidden or 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
/* | |
to calculate prime numbers using sieve of erosthenes | |
@author:rohit | |
*/ | |
#include <iostream> | |
#include <stdio.h> | |
#include <cmath> |
This file contains hidden or 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> | |
#include <stdio.h> | |
#include <vector> | |
#include <set> | |
#include <algorithm> | |
using namespace std; | |
class Robertherb{ | |
public: |
This file contains hidden or 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> | |
#include <stdio.h> | |
#include <vector> | |
#include <cmath> | |
typedef long long int LL; | |
#define MAX 100100 | |
LL arr[MAX]; | |
using namespace std; |
OlderNewer