#include <string> #include <vector> #include <algorithm> #include <iostream> using namespace std; vector<int> allDates; vector<int> allSupplies; bool check[100001]; int limit; int result; void DFS(int stock, int dayCount, int count) { if(dayCount == allDates.size()) { if (limit - allDates[dayCount - 1] <= stock) { result = result > count ? count : result; } else if (limit - allDates[dayCount - 1] <= stock){ result = result > count + 1 ? count + 1 : result; } return; } if(stock - (allDates[dayCount] - allDates[dayCount - 1]) >= 0) { DFS(stock - (allDates[dayCount] - allDates[dayCount - 1]), dayCount + 1, count); DFS(stock - (allDates[dayCount] - allDates[dayCount - 1]) + allSupplies[dayCount], dayCount + 1, count + 1); } } int solution(int stock, vector<int> dates, vector<int> supplies, int k) { int answer = 0; fill(check, check + 100001, false); allDates.clear(); allDates.assign(dates.begin(), dates.end()); allDates.insert(allDates.begin(), 0); allSupplies.clear(); allSupplies.assign(supplies.begin(), supplies.end()); allSupplies.insert(allSupplies.begin(), 0); limit = k; result = 100001; DFS(stock, 1, 0); answer = result; return answer; } | cs |
'problem solving' 카테고리의 다른 글
[미완]디스크 분할 (0) | 2020.03.13 |
---|---|
[프로그래머스]라면공장 (0) | 2020.03.13 |
[프로그래머스]여행경로 (0) | 2020.03.13 |
[프로그래머스]단어 변환 (0) | 2020.03.12 |
[프로그래머스]네트워크 (0) | 2020.03.12 |