Skip to content

Instantly share code, notes, and snippets.

View mryoshio's full-sized avatar

YOSHIOKA A mryoshio

View GitHub Profile
@mryoshio
mryoshio / lcs_naive.cpp
Created February 24, 2014 16:33
Naive implementation of LCS
#include <iostream>
#include <string>
using namespace std;
int N, M;
string S, T;
int calc(int n, int m) {
if (n == N || m == M)
@mryoshio
mryoshio / lcs_memo.cpp
Created February 24, 2014 16:35
Implementation of LCS with memo
#include <iostream>
#include <string>
#include "../d.h"
using namespace std;
int N, M;
string S, T;
int dp[1001][1001];
@mryoshio
mryoshio / lcs_dp.cpp
Created February 24, 2014 16:36
DP of LCS
#include <iostream>
#include <string>
#include "../d.h"
using namespace std;
int N, M;
string S, T;
int dp[1001][1001];
@mryoshio
mryoshio / compress_decompress.rb
Created March 1, 2014 13:53
compress, decompress
def decompress(args)
ans = []
args.each do |a|
if a.is_a? Array
ans.push a.last*a.first
else
ans.push a
end
end
ans.join("")
@mryoshio
mryoshio / sum.cpp
Created March 9, 2014 05:41
sum.cpp
template<typename Container, typename Value>
Value sum(const Container& c, Value v)
{
for (auto x : c)
v += x;
return v;
}
#include <iostream>
#include <string>
using namespace std;
class person {
private:
int age;
string name;
public:
@mryoshio
mryoshio / variadic_template.cpp
Created April 5, 2014 08:37
variadic template sample
void f() {} // do nothing
template<typename T, typename... Tail>
void f(T head, Tail... tail)
{
g(head); // headに対し何かする
f(tail...); // 再度tailに対し実行
}
@mryoshio
mryoshio / variadic_template2.cpp
Created April 5, 2014 08:48
variadic template sample2
int main()
{
cout << "first: ";
f(1, 2.2, "hello");
cout << "\nsecond: ";
f(0.2, 'c', "yuck!", 0, 1, 2);
cout << "\n";
}
@mryoshio
mryoshio / bst.cpp
Created April 19, 2014 07:08
play binary search tree
#include <iostream>
#include <stack>
using namespace std;
class Node {
public:
int val;
Node *left, *right;
Node(int v): val(v) {}
@mryoshio
mryoshio / regex_search_sample.cpp
Last active August 29, 2015 14:00
regex_search() sample
#include <iostream>
#include <fstream>
#include <regex>
using namespace std;
/*
Usage: $ g++ -std=c++11 regex_search_sample.cpp && ./a.out
// example