Skip to content

Instantly share code, notes, and snippets.

View tchomphoochan's full-sized avatar

Thanadol (Pleng) Chomphoochan tchomphoochan

View GitHub Profile
Require Import List Lia Arith.
Import ListNotations.
Fixpoint prefix_sum (l : list nat) :=
match l with
| nil => nil
| cons d l' => cons d (map (fun x => x+d) (prefix_sum l'))
end.
Goal prefix_sum [3; 2; 7; 6; 8] = [3; 5; 12; 18; 26].

Keybase proof

I hereby claim:

  • I am tchomphoochan on github.
  • I am tcpc (https://keybase.io/tcpc) on keybase.
  • I have a public key whose fingerprint is FAD6 4375 6D8E E9D9 E4A8 595C 5A05 4AC1 4D33 3C67

To claim this, I am signing this object:

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]);
}
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;
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
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;
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
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];
@tchomphoochan
tchomphoochan / sample.txt
Created September 27, 2018 10:38
TechJam 2018 Regional Competition Code Track (North)
7 7
.......
..####.
.#...#.
.#.#.#.
.#...#.
.#####.
.......
@tchomphoochan
tchomphoochan / edgecase-islands.txt
Created September 27, 2018 10:37
TechJam 2018 Regional Competition Code Track (North)
!A!B
AAA!
!AAA
C!A!