Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 투포인터
- 백준
- COS PRO
- 건강
- 문자열
- 이분탐색
- Java
- 자바
- DP
- priorityqueue
- BOJ
- 코딩테스트
- 문제풀이
- dfs
- BFS
- SWEA
- 러닝일지
- 프로그래머스
- oracle
- db
- binary search
- 문제해결
- 시뮬레이션
- 코테
- 운동기록
- SQL
- 알고리즘
- math
- greedy
- MySQL
Archives
- Today
- Total
슈콩
[SWEA] 2일차 - 최대상금 본문


[문제]
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV15Khn6AN0CFAYD
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
[소스 코드]
import java.util.*;
import java.io.*;
public class Solution {
static int max,result = 0;
static char[] nums;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int T = Integer.parseInt(br.readLine());
for(int tc=1;tc<=T;tc++) {
st = new StringTokenizer(br.readLine());
String num = st.nextToken();
nums = new char[num.length()];
for(int i=0;i<num.length();i++) {
nums[i] = num.charAt(i);
}
max = Integer.parseInt(st.nextToken());
result = 0;
dfs(0,0);
System.out.println("#"+tc+" "+result);
}
}
private static void dfs(int idx,int cnt) {
if(cnt==max) {
int number = Integer.valueOf(new String(nums));
result = Math.max(result, number);
return;
}
for(int i=idx;i<nums.length;i++) {
for(int j=i+1;j<nums.length;j++) {
swap(i,j);
dfs(i,cnt+1);
swap(j,i);
}
}
}
private static void swap(int i,int j) {
char temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}'Algorithms > SWEA' 카테고리의 다른 글
| [SWEA] 농작물 수확하기 (0) | 2025.11.03 |
|---|---|
| [SWEA] N-Queen (0) | 2025.10.30 |
| [SWEA] 1일차 - Flattern (0) | 2025.10.30 |
| [SWEA] 햄버거 다이어트 (0) | 2025.10.30 |
| [SWEA] 1일차 - VIEW (0) | 2025.10.30 |