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 | 
                            Tags
                            
                        
                          
                          - directx
 - 티스토리챌린지
 - 1563
 - 프로그래머스
 - RVO
 - 팰린드롬 만들기
 - TObjectPtr
 - Programmers
 - Frustum
 - C
 - winapi
 - C++
 - NRVO
 - baekjoon
 - 오블완
 - const
 - 줄 세우기
 - GeeksForGeeks
 - 백준
 - Unreal Engine5
 - UnrealEngine4
 - 2294
 - softeer
 - UnrealEngine5
 - IFileDialog
 - UE5
 - DirectX11
 - RootMotion
 - algorithm
 - 언리얼엔진5
 
                            Archives
                            
                        
                          
                          - Today
 
- Total
 
Game Develop
[Algorithm]Baekjoon 19942번 :: 다이어트 본문
https://www.acmicpc.net/problem/19942
| 
 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 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
 | 
 #include <iostream> 
#include <string> 
#include <map> 
#include <vector> 
#include <algorithm> 
#include <math.h> 
#include <queue> 
#include <functional> 
#include <sstream> 
#include <memory.h> 
#include <deque> 
#include <set> 
#include <unordered_set> 
#include <thread> 
#include <atomic> 
using namespace std; 
struct Food 
{ 
    int p, f, s, v, c; 
}; 
int n, mp, mf, ms, mv; 
vector<Food> foods(16); 
const int maxNum = 0x3f3f3f3f; 
int answer = maxNum; 
vector<int> curRoute; 
vector<int> answerRoute; 
void DFS(int index, int p, int f, int s, int v, int c) 
{ 
    if (p >= mp && f >= mf && s >= ms && v >= mv) 
    { 
        if (c < answer) 
        { 
            answer = c; 
            answerRoute = curRoute; 
        } 
        return; 
    } 
    if (index == n) return; 
    // 선택 
    curRoute.push_back(index + 1); 
    DFS(index + 1, p + foods[index].p, f + foods[index].f,  
        s + foods[index].s, v + foods[index].v, c + foods[index].c); 
    curRoute.pop_back(); 
    // 안선택 
    DFS(index + 1, p, f, s, v, c); 
} 
int main() 
{ 
    ios::sync_with_stdio(false); 
    cin.tie(0); 
    cout.tie(0); 
    cin >> n; 
    cin >> mp >> mf >> ms >> mv; 
    for (int i = 0; i < n; ++i) 
    { 
        cin >> foods[i].p >> foods[i].f >> foods[i].s >> foods[i].v >> foods[i].c; 
    } 
    DFS(0, 0, 0, 0, 0, 0); 
    if (answer == maxNum) cout << -1; 
    else 
    { 
        cout << answer << endl; 
        for (int i = 0; i < answerRoute.size(); ++i) 
        { 
            printf("%d ", answerRoute[i]); 
        } 
    } 
} 
 | 
cs | 
골드4지만 정답률이 25%길래 한번 풀어봤는데, 딱히 특별하게 다른 문제는 아니였다.
각 식품을 선택,안선택하면서 완전탐색을 진행하면 되고, 루트도 알아야하기 때문에 선택할때마다 푸쉬해서 answer를 갱신할 때, 갱신할만하면 answerRoute에 복사해주면 된다.
N값이 작아서 충분히 0ms로 통과한다.
'Algorithm > Baekjoon' 카테고리의 다른 글
| [Algorithm]Baekjoon 9207번 :: 페그 솔리테어 (0) | 2024.11.06 | 
|---|---|
| [Algorithm]Baekjoon 9944번 :: NxM 보드 완주하기 (0) | 2024.11.04 | 
| [Algorithm]Baekjoon 17136번 :: 색종이 붙이기 (0) | 2024.11.03 | 
| [Algorithm]Baekjoon 18430번 :: 무기 공학 (0) | 2024.10.30 | 
| [Algorithm]Baekjoon 13422번 :: 도둑 (0) | 2024.10.25 | 
          