티스토리 뷰
반응형
백준 1463번 1로 만들기
https://www.acmicpc.net/problem/1463
1463번: 1로 만들기
첫째 줄에 1보다 크거나 같고, 106보다 작거나 같은 정수 N이 주어진다.
www.acmicpc.net


정답 코드
#include<iostream>
using namespace std;
int arr[1000001];
int main() {
int t;
cin >> t;
for (int x = 2; x <= t; x++) {
arr[x] = arr[x - 1] + 1;
if (x % 3 == 0)
arr[x] = min(arr[x], arr[x / 3] + 1);
if (x % 2 == 0)
arr[x] = min(arr[x], arr[x / 2] + 1);
}
cout << arr[t];
}
반응형
'Algorithm > BOJ' 카테고리의 다른 글
백준 1546번 C++ (0) | 2023.07.24 |
---|---|
백준 1476번 C++ (0) | 2023.07.24 |
백준 1431번 C++ (0) | 2023.07.24 |
백준 1427번 C++ (0) | 2023.07.23 |
백준 1406번 C++ (0) | 2023.07.23 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 반복문
- html
- 자료구조
- 유클리드 호제법
- 스프링 부트 crud 게시판 구현
- c++ string
- C++
- java
- 우선순위 큐
- DP
- CSS
- js
- 백준 풀이
- DFS
- 에라토스테네스의 체
- BFS
- 투 포인터
- 자바
- C++ Stack
- 유니온 파인드
- 스택
- 자바스크립트
- Do it!
- 알고리즘
- 카운팅 정렬
- 백준
- HTML5
- 알고리즘 공부
- 이분 매칭
- 세그먼트 트리
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함