-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStamina.java
52 lines (39 loc) · 1.26 KB
/
Stamina.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package programmers;
class Solution {
static int tmp[][];
static int max = Integer.MIN_VALUE;
public static int solution(int k, int[][] dungeons) {
Solution.permutation(dungeons,0, dungeons.length,dungeons.length,k);
return max;
}
static void permutation(int[][] arr, int depth, int n, int r, int k) {
if (depth == r) {
check(arr, r, k);
return;
}
for (int i=depth; i<n; i++) {
swap(arr, depth, i);
permutation(arr, depth + 1, n, r,k);
swap(arr, depth, i);
}
}
static void swap(int[][] arr, int depth, int i) {
int minumunSta = arr[depth][0];
arr[depth][0] = arr[i][0];
arr[i][0] = minumunSta;
int need = arr[depth][1];
arr[depth][1] = arr[i][1];
arr[i][1] = need;
}
static void check(int[][] arr, int r, int userStamina) {
int ableDungeons = 0;
for (int i = 0; i < r; i++) {
// System.out.print("["+arr[i][0] + "," + arr[i][1] + "] " );
if(userStamina >= arr[i][0]){
userStamina -= arr[i][1];
ableDungeons++;
}
}//System.out.println();
if(ableDungeons > max) max = ableDungeons;
}
}