Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object NewYearsResolution extends App {
- import scala.io.StdIn._
- import collection.mutable._
- case class Return[T](obj: T) extends Exception
- def ret[T](obj: T) = throw Return(obj)
- val T = readInt
- for (caseNb <- 1 to T) {
- def read = readLine split " " map (_ toInt)
- val Array(gp, gc, gf) = read
- val N = readInt
- val foods = ArrayBuffer[(Int,Int,Int)]()
- for (i <- 0 until N) {
- val Array(p, c, f) = read
- foods += ((p, c, f))
- }
- val eaten = Array.fill(foods.size)(false)
- def search(p: Int, c: Int, f: Int) {
- if (p == gp && c == gc && f == gf) ret("yes")
- if (p <= gp && c <= gc && f <= gf)
- for (i <- 0 until eaten.size if !eaten(i)) {
- eaten(i) = true
- search(p + foods(i)._1, c + foods(i)._2, f + foods(i)._3)
- eaten(i) = false
- }
- }
- val r = try { search(0,0,0); "no" }
- catch { case Return(ans) => ans }
- println(s"Case #$caseNb: $r")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement