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
!#!# | |
#.#! | |
!#.# | |
#!#! |
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
4 4 | |
.#.# | |
#.#. | |
.#.# | |
#.#. |
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
!A!B | |
AAA! | |
!AAA | |
C!A! |
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
7 7 | |
....... | |
..####. | |
.#...#. | |
.#.#.#. | |
.#...#. | |
.#####. | |
....... |
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
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]; | |
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
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 |
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
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; |
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
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 |
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
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; |
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
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]); | |
} |
OlderNewer