import scala.collection.mutable.ArrayBuffer
import scala.util.control.Breaks
object Exchange {
def delete(arg:ArrayBuffer[Int]):ArrayBuffer[Int]={
val breakables = new Breaks
breakables.breakable {
for (i <- 0 until arg.length) {
if (arg(i) == arg.max) {
arg.remove(i)
breakables.break()
}
}
}
arg
}
def exchange(total:Int,money:ArrayBuffer[Int]):Int={
if (total==0)
1
else if(total<0||money.length==0)
0
else{
//var newMoney=money这种赋值方式,newMoney其实不是一个新的数组
val newMoney = for(elem <- money) yield elem
delete(newMoney)
exchange((total-money.max),money)+exchange(total,newMoney)
}
}
def main(args:Array[String]): Unit ={
val ab = ArrayBuffer[Int](50,20,10,5,2,1)
println(exchange(100,ab))
}
}