Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

35-H0ngJu #258

Merged
merged 3 commits into from
Dec 1, 2024
Merged

35-H0ngJu #258

merged 3 commits into from
Dec 1, 2024

Conversation

H0ngJu
Copy link
Collaborator

@H0ngJu H0ngJu commented Nov 23, 2024

πŸ”— 문제 링크

전깃쀄

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

μΈ‘μ •λΆˆκ°€

✨ μˆ˜λ„ μ½”λ“œ

image



κΈˆμš”μΌμ— μ‹œμž‘ν•΄μ„œ,, ν‹ˆλ‚  λ•Œλ§ˆλ‹€ 계속 고민을 ν–ˆλŠ”λ°μš”

μ ‘κ·Ό 방법이 1도 λ– μ˜€λ₯΄μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.
κ΅¬ν˜„λ„ μ•„λ‹Œ 것 κ°™κ³ ,, 무슨 μ•Œκ³ λ¦¬μ¦˜μ„ μ¨μ•Όν•˜λŠ”μ§€ κ°€λ‹₯이 μ•ˆλ³΄μ΄λ”λΌκ³ μš”.

image


일단 λ¬Έμ œμ—μ„œ 주어진 μ˜ˆμ‹œλ‘œ 보면,

μ„œλ‘œ μ—°κ²°λœ A와 Bκ°€ λ‹€μŒ μ „κΉƒμ€„μ˜ A B보닀 μž‘μœΌλ©΄ κ²ΉμΉ˜μ§€ μ•ŠκΈ° λ•Œλ¬Έμ— ν•΄λ‹Ή λ°©μ‹μœΌλ‘œ μ—†μ• μ•Ό ν•  μ΅œμ†Œ 전깃쀄을 μ…€ 수 μžˆμ§€ μ•Šμ„κΉŒ? ν–ˆμŠ΅λ‹ˆλ‹€.

(전깃쀄 μ—°κ²° 정보듀은 sortν–ˆλ‹€κ³  κ°€μ •ν•˜κ² μŠ΅λ‹ˆλ‹€)

ν•˜μ§€λ§Œ μ•„λž˜μ˜ μΌ€μ΄μŠ€μ—μ„œ μ˜ˆμ™Έκ°€ λ°œμƒν•©λ‹ˆλ‹€.


image

정보듀을 λ‚΄λ¦Όμ°¨μˆœμœΌλ‘œ μ •λ ¬ν•˜κ³ , ν•˜λ‚˜μ”© κΊΌλ‚Έλ‹€λŠ” 가정이면,
5 - 1이 λ¨Όμ € 선택이 λ˜μ—ˆκ³ , λ‚¨μ•„μžˆμ„ κ²½μš°λŠ” A < 5 and B < 1μž…λ‹ˆλ‹€.
ν•΄λ‹Ή 둜직의 κ²°κ³ΌλŠ” μ—†μ• μ•Όν•  μ΅œμ†Œ 전깃쀄이 4κ°€ λ©λ‹ˆλ‹€.

μ‹€μ œλ‘œλŠ” 1인데 말이죠..
정렬을 μ˜€λ¦„μ°¨μˆœμ„ ν•œλ‹€ν•΄λ„ μœ„ μ˜ˆμ‹œμ—μ„œ 1-5κ°€ μ—°κ²°λœ μƒνƒœλΌλ©΄ μ—­μ‹œ 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€.



κ·Έλ ‡κ²Œ,, 계속 계속 κ³ λ―Όν–ˆλŠ”λ°,,,
아무리 생각해도

무엇을 λ¨Όμ € μ²΄ν¬ν•˜λƒμ— 따라 그에 λŒ€ν•œ 영ν–₯이 λ’· 쀄에도 갈 수 밖에 μ—†λŠ”λ°,,
κ·Έλ¦¬λ””ν•˜κ²Œ μ ‘κ·Όν•΄μ•Όν•˜λŠ” λ¬Έμ œμΈκ°€?? ν•˜λ©΄μ„œ 머리가 ν„°μ‘ŒμŠ΅λ‹ˆλ‹€..

λ¨Όκ°€ μ•„ 될듯말듯 될듯말듯 될듯말듯


κ²°κ΅­ 였늘 μ•„μΉ¨λ˜μ„œμ•Ό 레퍼런슀 ν™•μΈν–ˆλ„€μš”

κ²°λ‘  λΆ€ν„° λ§ν•˜λ©΄ DPμž…λ‹ˆλ‹€........................
LIS κ°œλ…μ΄ λ“€μ–΄κ°€μš”

각 전깃쀄을 νƒν•˜κ³ 
ν•΄λ‹Ή 전깃쀄이 λ§ˆμ§€λ§‰ μ „κΉƒ 쀄이라고 μƒκ°ν•˜κ³  κ²ΉμΉ˜μ§€ μ•Šκ²Œ λ§Œλ“€ 수 μžˆλŠ” μΌ€μ΄μŠ€λ₯Ό dp에 μ €μž₯ν•©λ‹ˆλ‹€.
-> μ΄λ•Œ 쑰건은 μ•ž μ „κΉƒμ€„μ˜ B < ν˜„μž¬ 전깃쀄 Bμž…λ‹ˆλ‹€.

κ°€μž₯ κΈ΄ μ¦κ°€ν•˜λŠ” λΆ€λΆ„ μˆœμ—΄
μ‘μš© 문제 인 것 κ°™λ„€μš”.



DP둜 ν’€μ–΄μ•Όν•˜λŠ” 건 쀄은 μ§„μ§œ 생각도 λͺ»ν–ˆλ„€μš” 🀯

import sys

def input() : return sys.stdin.readline().rstrip()

N = int(input())
info = [list(map(int, input().split())) for _ in range(N)]

info.sort()

LIS = [1] * N

for i in range(1, N):
    for j in range(i):
        if info[j][1] < info[i][1]:
            LIS[i] = max(LIS[i], LIS[j] + 1)

print(N-max(LIS))

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

@tgyuuAn
Copy link
Member

tgyuuAn commented Dec 1, 2024

와 잠깐,,, 이 문제 μ˜ˆμ „μ— ν’€μ—ˆμ—ˆλŠ”λ° μ§€κΈˆ λ‹€μ‹œ λ³΄λ‹ˆκΉŒ λ‡Œμ •μ§€μ™€μ„œ

LIS인거도 ν™•μΈν•˜κ³  풀라고해쓷넀 μ•ˆν’€λ¦¬λŠ”λ°,,,

Copy link
Member

@tgyuuAn tgyuuAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import java.util.*;
import kotlin.math.*;

fun main() {
    val linesCount = readln().toInt()
    val lines = mutableListOf<Pair<Int, Int>>()
    
    repeat(linesCount) {
        val (x,y) = readln().split(" ")
        .map{ it.toInt() }
        
        lines.add(x to y)
    }
    
    val sortedLines = lines.sortedBy({it.first}).map{ it.second }
    
    val dp = IntArray(linesCount) { 1 }

    for(idx in 1 until lines.size){
        val now = sortedLines[idx]
        
        for(prevIdx in 0 until idx){
            val prevValue = sortedLines[prevIdx]
            
            if(prevValue < now){
                dp[idx] = max(dp[idx], dp[prevIdx]+1)
            }
        }
    }
    
    println(linesCount - dp.max())
}

와 λΆ„λͺ… μ˜ˆμ „μ— ν’€μ—ˆλ˜ 문젠데 λ‹€μ‹œ λ³΄λ‹ˆκΉŒ κΈ΄κ°€λ―Όκ°€ ν•΄μ„œ...

LIS인거도 μ•Œκ³ μžˆμ—ˆλŠ”λ°,,, μ•ˆν’€λ¦¬λ”λΌκ³ μš”....

덕뢄에 λ¦¬λ§ˆμΈλ“œ μž˜ν–ˆμŠ΅λ‹ˆλ‹€.... 땑베감~~~~~~~~

import java.util.*;

fun main() {
    val linesCount = readln().toInt()
    val lines = mutableListOf<Pair<Int, Int>>()
    
    repeat(linesCount) {
        val (x,y) = readln().split(" ")
        .map{ it.toInt() }
        lines.add(x to y)
    }
    
    val sortedLines = lines.sortedBy({it.first}).map{ it.second }
    val lis = mutableListOf(sortedLines[0])
    for(idx in 1 until lines.size){
        val now = sortedLines[idx]
        
        if(lis.last() < now) {
            lis.add(now)
            continue
        }
        
        var left = -1
        var right = lis.size
        while (left+1<right) {
            val mid = (left+right)/2
            
            if(check(lis, mid, now)){
                left = mid
            } else {
                right = mid
            }
        }

        lis[left+1] = now
    }

    println(linesCount - lis.size)
}

fun check(lis:List<Int>, mid:Int, elem:Int): Boolean {
    if(lis[mid] < elem){
        return true
    }
    
    return false
}

μœ„μ—κ»€ DPμ•ˆμ“°κ΅¬ μ΄λΆ„νƒμƒ‰μœΌλ‘œ μ¨μ„œ μ‹œκ°„μ„ 더 쀄인 LIS!!!

@H0ngJu H0ngJu merged commit d494d98 into main Dec 1, 2024
5 checks passed
@H0ngJu H0ngJu deleted the 35-H0ngJu branch December 1, 2024 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants