Skip to content

[Week4] 전현수: 근손실, 톱니바퀴, 트리의 부모 찾기, 회의실 배정, 지름길 #18

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Feat: 근손실 추가
  • Loading branch information
soopeach committed Oct 23, 2022
commit abe70a39f2684cb1185f85756e8b36045d99bf23
62 changes: 62 additions & 0 deletions src/4week/hyunsoo/근손실.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package `4week`.hyunsoo

class 전현수_근손실{
/**
* <문제>
* [근손실](https://www.acmicpc.net/problem/18429)
*
* 하루가 지나면 중량이 K만큼 감소
* N개의 서로 다른 운동 키트를 가지고 있음.
* 하루에 1개씩 키트를 사용. 사용하면 중량이 즉시 증가
* 운동 키트를 사용하면서 항상 중량이 500이상이 되도록 해야함.
*
* 아이디어
* - 완탐해서 모든 조합을 구하고
* - 각 조합들로 운동할 경우 500이상이 되는지를 판정하자!
*
*/

val exerciseKitList = mutableListOf<Int>()
Copy link
Member

Choose a reason for hiding this comment

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

이런부분 lateinit 해주세요!!!!!!

var possibleCaseCnt = 0
val exerciseCase = mutableListOf<Int>()
val visited = BooleanArray(8) { false }

fun solution() {

val (exerciseCnt, downWeight) = readln().split(" ").map { it.toInt() }
val exerciseData = readln().split(" ").map { it.toInt() }
exerciseKitList.addAll(exerciseData)

checkAllCases(0, exerciseCnt, downWeight)

println(possibleCaseCnt)
}

fun checkAllCases(cnt: Int, depth: Int, downWeight: Int) {

if (cnt == depth) {

var curWeight = 500
exerciseCase.forEach { upWeight ->
curWeight += upWeight - downWeight
if (curWeight < 500) return
}
possibleCaseCnt++
return
}
for (index in 0 until exerciseKitList.size) {
Copy link
Member

Choose a reason for hiding this comment

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

이부분 exerciseKitList.forEachIndexed 했으면 어땠을까요?

if (visited[index]) continue

visited[index] = true
exerciseCase.add(exerciseKitList[index])
checkAllCases(cnt + 1, depth, downWeight)
visited[index] = false
exerciseCase.removeAt(exerciseCase.lastIndex)
}
}
}

fun main(){
val myClass = 전현수_근손실()
myClass.solution()
}