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
- mysqld.sock
- MySQL
- 영상 프레임 추출
- 3273
- 원형
- 2020 KAKAO BLIND RECRUITMENT
- 18249
- 수 만들기
- 3344
- 그리디알고리즘
- 백준
- 강의실2
- 알고리즘 목차
- c#
- 탄막 이동
- 토글 그룹
- 걷는건귀찮아
- 탄막
- 자료구조 목차
- 회의실 배정
- SWEA
- 유니티
- 탄막 스킬 범위
- 알고리즘
- AI Hub
- 단어 수학
- 문자열 압축
- 윈도우
- 우분투
- 마우스 따라다니기
Archives
- Today
- Total
와이유스토리
[DFS 단순] 프로그래머스 타겟 넘버 C++ 본문
https://programmers.co.kr/learn/courses/30/lessons/43165
코딩테스트 연습 - 타겟 넘버
n개의 음이 아닌 정수들이 있습니다. 이 정수들을 순서를 바꾸지 않고 적절히 더하거나 빼서 타겟 넘버를 만들려고 합니다. 예를 들어 [1, 1, 1, 1, 1]로 숫자 3을 만들려면 다음 다섯 방법을 쓸 수
programmers.co.kr
#include <string>
#include <vector>
using namespace std;
int answer = 0;
void dfs(vector<int> numbers, int target, int idx, int cal) {
if (idx == numbers.size())
{
if (target == cal)
{
answer++;
}
return;
}
dfs(numbers, target, idx+1, cal+numbers[idx]);
dfs(numbers, target, idx+1, cal-numbers[idx]);
return;
}
int solution(vector<int> numbers, int target) {
dfs(numbers, target, 0, 0);
return answer;
}
'코딩테스트 > 그래프|트리' 카테고리의 다른 글
[DFS 순열] 프로그래머스 단어 변환 C++ (0) | 2022.01.20 |
---|---|
[DFS 단순 반복] 프로그래머스 네트워크 C++ (0) | 2022.01.20 |
[DFS, BFS] 백준 12100 2048(Easy) C++ (0) | 2022.01.06 |
[DFS 조합 반복] 프로그래머스 메뉴 리뉴얼 C++ (0) | 2022.01.01 |
[DFS 순열] 프로그래머스 단체사진 찍기 C++ (0) | 2021.12.31 |
Comments