Skip to content

Instantly share code, notes, and snippets.

View tchomphoochan's full-sized avatar

Thanadol (Pleng) Chomphoochan tchomphoochan

View GitHub Profile
@tchomphoochan
tchomphoochan / edgecase-fillout.txt
Last active September 27, 2018 10:36
TechJam 2018 Regional Competition Code Track (North)
!#!#
#.#!
!#.#
#!#!
@tchomphoochan
tchomphoochan / edgecase.txt
Created September 27, 2018 10:36
TechJam 2018 Regional Competition Code Track (North)
4 4
.#.#
#.#.
.#.#
#.#.
@tchomphoochan
tchomphoochan / edgecase-islands.txt
Created September 27, 2018 10:37
TechJam 2018 Regional Competition Code Track (North)
!A!B
AAA!
!AAA
C!A!
@tchomphoochan
tchomphoochan / sample.txt
Created September 27, 2018 10:38
TechJam 2018 Regional Competition Code Track (North)
7 7
.......
..####.
.#...#.
.#.#.#.
.#...#.
.#####.
.......
int memo[MAX_N]; // initially set all to -1 to mark as "not done yet"
int change(int i) {
// base cases:
if (i == 0) return 0;
if (i < 0) return 1e9; // 1e9 = 1,000,000,000
// already solved cases:
if (memo[i] != -1)
return memo[i];
int ans[MAX_N];
ans[0] = 0; // base case
for (int i = 1; i <= n; ++i) {
ans[i] = 1e9; // don't know a way to solve yet
if (i-1 >= 0) // try using 1-baht coin if possible
ans[i] = min(ans[i], 1+ans[i-1]);
if (i-3 >= 0) // try using 3-baht coin if possible
ans[i] = min(ans[i], 1+ans[i-3]);
if (i-4 >= 0) // try using 4-baht coin if possible
char A[MAX_N][MAX_M]; // assume the board's data is in A[1.n][1..m]
int dp[MAX_N][MAX_M]; // initially set all to -1 to mark as "not done yet"
int count_paths(int i, int j) {
if (i < 1 || j < 1)
return 0;
if (A[i][j] == '#')
return 0;
if (i == 1 && j == 1)
return 1;
char A[MAX_N][MAX_M]; // assume the board's data is in A[1..n][1..m]
int dp[MAX_N][MAX_M]; // set everything to 0 (so dp[0][0..m] and dp[0..n][0] will be 0)
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (A[i][j] == '#')
dp[i][j] = 0;
else if (i == 1 && j == 1)
dp[i][j] = 1;
else
int A[MAX_N];
int dp[MAX_N]; // dp[0] = 0
int ans = -1e9;
for (int i = 1; i <= n; ++i) {
dp[i] = max(A[i], dp[i-1]+A[i]);
ans = max(ans, dp[i]);
}
cout << ans << endl;
int A[MAX_N]; // assume data is in A[1..n]
int dp[MAX_N];
int ans = 0;
for (int i = 1; i <= n; ++i) {
dp[i] = 1;
for (int j = 1; j < i; ++j) {
if (A[j] < A[i])
dp[i] = max(dp[i], 1+dp[j]);
}