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
/* References : | |
http://www.geeksforgeeks.org/dynamic-programming-set-3-longest-increasing-subsequence/ | |
https://www.youtube.com/watch?v=4fQJGoeW5VE */ | |
#include <iostream> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; |
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
/* Performance of qsort, worst case O(n log n) | |
Example input : | |
3 | |
4 9 | |
-3 48 | |
-100 48 | |
Example output : |
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
/* example input-output | |
input : | |
abc | |
expected output : | |
1 => | |
2 => a | |
3 => b | |
4 => ab |
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 <stdio.h> | |
#include <string.h> | |
#define max(X,Y) ((X) > (Y)) ? (X) : (Y) | |
typedef struct item | |
{ | |
int value; | |
int weight; | |
} Item; |
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 <stdio.h> | |
#include <math.h> | |
#define SIZE 100 | |
unsigned __int128 fact(int N) // calculate factorial with O(n) | |
{ | |
static unsigned __int128 memo[SIZE] = {-1}; | |
if(memo[N] > -1) return memo[N]; | |
else return memo[N] = (N <= 1) ? 1 : fact(N-1) + fact(N-2); |
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 <stdio.h> | |
typedef unsigned __int128 uint128; | |
/* printing 128-bit value isn't official support yet | |
so here's implementation of converting 128-bit value into string */ | |
char *str_uint128(uint128 n) | |
{ | |
/* got confused about arithmetic operation with '0'? read more about ascii :) */ | |
static char buf[1000] = {0}, *buft = buf; |
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
# recursive method | |
def lcs(a, b): | |
if(len(a) <= 0 or len(b) <= 0): | |
return 0 | |
elif(a[-1] == b[-1]): | |
return lcs(a[:-1], b[:-1]) + 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
#include <stdio.h> | |
int main() | |
{ | |
char D[2], M[2], Y[4], name[100]; // char string | |
printf("Please enter your birthdate (DDMMYYYY): "); | |
scanf("%2s%2s%4s", D, M, Y); | |
printf("Please enter your name : "); |
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
import java.math.BigInteger; | |
import java.util.Scanner; | |
public class i | |
{ | |
public static void main(String args[]) | |
{ | |
Scanner in = new Scanner(System.in); | |
int T, N, K; |
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; | |
// cara nk buat function biasa | |
// return = output calculation tu | |
double f(double x, double y) | |
{ | |
return 2 * x * y; | |
} |