[D3] [S/W 문제해결 응용] 2일차 - 최대 상금 - 1244
성능 요약
메모리: 107,660 KB, 시간: 8,832 ms, 코드길이: 1,063 Bytes
제출 일자
2023-11-07 13:27
출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do
import java.util.*;
import java.io.*;
class Solution {
static char[] nums;
static int limitCount;
static int result;
public static void main(String args[]) throws Exception{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int tc = 1; tc <= T; tc++){
nums = sc.next().toCharArray();
limitCount = sc.nextInt();
result = 0;
dfs(0,0);
System.out.println("#" + tc + " " + result);
}
}
private static void dfs(int pos,int count){
if(count == limitCount){
int value = Integer.parseInt(new String(nums));
result = Math.max(result,value);
return;
}
for(int i = pos; i < nums.length; i++){
for(int j =i + 1; j < nums.length; j++){
swap(i,j);
dfs(i,count+1);
swap(i,j);
}
}
}
private static void swap(int i, int j){
char tmp = nums[i];
nums[i] = nums[j];
nums[j] = tmp;
}
}
'알고리즘 - SWEA > D3' 카테고리의 다른 글
[SW expert Academy] SWEA 1240번 단순 2진 암호코드 자바(Java) (0) | 2023.11.08 |
---|---|
[SW expert Academy] SWEA 4615번 재미있는 오셀로 게임 자바(Java) (0) | 2023.11.07 |
[SW expert Academy] SWEA 9658번 유효숫자 표기 자바(Java) (0) | 2023.11.07 |
[SW expert Academy] SWEA 9280번 진용이네 주차타워 자바(Java) (0) | 2023.11.07 |
[SW expert Academy] SWEA 7532번 세영이의 SEM력 연도 자바(Java) (0) | 2023.11.06 |