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
- SWEA
- 문제해결
- 운동기록
- oracle
- greedy
- 코딩테스트
- 자바
- 건강
- Java
- 프로그래머스
- 문제풀이
- 문자열
- 투포인터
- MySQL
- db
- 알고리즘
- SQL
- 백준
- 러닝일지
- math
- dfs
- 코테
- BFS
- BOJ
- COS PRO
- priorityqueue
- 이분탐색
- 시뮬레이션
- DP
- binary search
Archives
- Today
- Total
슈콩
[SWEA] 한빈이와 Spot Mart 본문


[문제]
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AW8Wj7cqbY0DFAXN
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
[소스 코드]
import java.io.*;
import java.util.*;
public class Solution {
static int n,m,result;
static int[] snack;
static boolean[] visit;
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());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
snack = new int[n];
visit = new boolean[n];
st = new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) {
snack[i] = Integer.parseInt(st.nextToken());
}
result = -1;
combi(0,0,0);
System.out.println("#"+tc+" "+result);
}
}
private static void combi(int idx,int cnt,int sum) {
if(sum>m) return;
if(cnt==2) {
if(sum<=m && sum>result)
result = sum;
return;
}
for(int i=idx;i<n;i++) {
if(!visit[i]) {
visit[i] = true;
combi(i+1,cnt+1,sum+snack[i]);
visit[i] = false;
}
}
}
}'Algorithms > SWEA' 카테고리의 다른 글
| [SWEA] 전봇대 (0) | 2025.11.12 |
|---|---|
| [SWEA] 1차원 정원 (0) | 2025.11.12 |
| [SWEA] 퍼펙트 셔플 (0) | 2025.11.12 |
| [SWEA] 민석이의 과제 체크하기 (0) | 2025.11.12 |
| [SWEA] 현주의 상자 바꾸기 (3) | 2025.11.12 |