피로도

피로도

import java.util. * ;

class Solution {

static int count = 0 ;

public static void dfs(ArrayList < int [] > allList, ArrayList < int [] > res, int k){

if (res.size() > count) {

count = res.size();

}

for ( int i = 0 ;i < allList.size();i + + ){

int [] dungeon = allList.get(i);

if (dungeon[ 0 ] < = k){

res. add (allList.remove(i));

dfs(allList, res, k - dungeon[ 1 ]);

allList. add (i, res.remove(res.size() - 1 ));

}

}

}

public int solution( int k, int [][] dungeons) {

int answer = - 1 ;

ArrayList < int [] > allList = new ArrayList < int [] > ();

for ( int i = 0 ;i < dungeons. length ;i + + ){

allList. add (dungeons[i]);

}

dfs(allList, new ArrayList < int [] > (), k);

answer = count;

return answer;

}

}

from http://zzunsik.tistory.com/213 by ccl(A) rewrite - 2021-10-25 18:27:51