Skip to content

Commit

Permalink
update LIS
Browse files Browse the repository at this point in the history
  • Loading branch information
kim6394 committed Aug 7, 2019
1 parent c327dba commit 0e0cbfd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
12 changes: 8 additions & 4 deletions Algorithm/LIS (Longest Increasing Sequence).md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ int dp[] = new int[arr.length]; // LIS ์ €์žฅ ๋ฐฐ์—ด


for(int i = 1; i < dp.length; i++) {
if(dp[i] == 0) dp[i] = 1;
for(int j = i-1; j>=0; j--) {
if(arr[i] > arr[i-1]) {
if(arr[i] > arr[j]) {
dp[i] = (dp[i] < dp[j]+1) ? dp[j]+1 : dp[i];
}
}
}
// ์ €์žฅ๋œ dp ๋ฐฐ์—ด ๊ฐ’ : [0, 1, 2, 3, 1, 4]
// LIS : dp๋ฐฐ์—ด์— ์ €์žฅ๋œ ๊ฐ’ ์ค‘ ์ตœ๋Œ€ ๊ฐ’

for (int i = 0; i < dp.length; i++) {
if(max < dp[i]) max = dp[i];
}

// ์ €์žฅ๋œ dp ๋ฐฐ์—ด ๊ฐ’ : [0, 0, 1, 2, 2, 3]
// LIS : dp๋ฐฐ์—ด์— ์ €์žฅ๋œ ๊ฐ’ ์ค‘ ์ตœ๋Œ€ ๊ฐ’ + 1
```

<br>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
- [๋จธ์ง€์†ŒํŠธ](https://github.com/kim6394/Dev_BasicKnowledge/blob/master/Algorithm/MergeSort.md)
- [ํž™์†ŒํŠธ](https://github.com/kim6394/Dev_BasicKnowledge/blob/master/Algorithm/HeapSort.md)
- [ํ•ด์‹œ ํ…Œ์ด๋ธ” ๊ตฌํ˜„](<https://github.com/kim6394/Dev_BasicKnowledge/blob/master/Algorithm/Hash%20Table%20%EA%B5%AC%ED%98%84%ED%95%98%EA%B8%B0.md>)
- [์ตœ์žฅ ์ฆ๊ฐ€ ์ˆ˜์—ด(LIS)]([https://github.com/kim6394/Dev_BasicKnowledge/blob/master/Algorithm/LIS%20(Longest%20Increasing%20Sequence).md](https://github.com/kim6394/Dev_BasicKnowledge/blob/master/Algorithm/LIS (Longest Increasing Sequence).md)

<br>

Expand Down
12 changes: 8 additions & 4 deletions TIL/19.08.07.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ int dp[] = new int[arr.length]; // LIS ์ €์žฅ ๋ฐฐ์—ด


for(int i = 1; i < dp.length; i++) {
if(dp[i] == 0) dp[i] = 1;
for(int j = i-1; j>=0; j--) {
if(arr[i] > arr[i-1]) {
if(arr[i] > arr[j]) {
dp[i] = (dp[i] < dp[j]+1) ? dp[j]+1 : dp[i];
}
}
}
// ์ €์žฅ๋œ dp ๋ฐฐ์—ด ๊ฐ’ : [0, 1, 2, 3, 1, 4]
// LIS : dp๋ฐฐ์—ด์— ์ €์žฅ๋œ ๊ฐ’ ์ค‘ ์ตœ๋Œ€ ๊ฐ’

for (int i = 0; i < dp.length; i++) {
if(max < dp[i]) max = dp[i];
}

// ์ €์žฅ๋œ dp ๋ฐฐ์—ด ๊ฐ’ : [0, 0, 1, 2, 2, 3]
// LIS : dp๋ฐฐ์—ด์— ์ €์žฅ๋œ ๊ฐ’ ์ค‘ ์ตœ๋Œ€ ๊ฐ’ + 1
```

<br>
Expand Down

0 comments on commit 0e0cbfd

Please sign in to comment.