12852
-
[BaekJoon] 12852๋ฒ : 1๋ก ๋ง๋ค๊ธฐ 2SW Test/BaekJoon 2021. 4. 19. 21:35
์ด ๊ธ์ c++๋ก ํ์ด๋ฅผ ์์ฑํ์์ต๋๋ค. ๋ฌธ์ ์์ ํ์ด BFS๋ฅผ ์ฌ์ฉํ ์ ์์ง๋ง DP๋ฅผ ํ์ฉํ์ฌ ๊ณต๊ฐ๋ณต์ก๋๋ฅผ ์ค์ผ ์ ์์ต๋๋ค. if i%2 != 0 && i%3 != 0, D[i] = D[i-1]+1 if i%2 == 0 && i%3 != 0, D[i] = min(D[i-1], D[i/2]) + 1 if i%2 == 0 && i%3 == 0, D[i] = min(D[i-1], D[i/2], D[i/3]) + 1 ๋ฐฉ๋ฒ์ ์ถ๋ ฅํ๊ธฐ ์ํด์๋ ๊ทธ ์ ์ซ์๋ฅผ ๋ด๋ prev ๋ฐฐ์ด์ ๋ง๋ค์ด์ผ ํฉ๋๋ค. 10 => prev[10] = 9, prev[9] = 3, prev[3] = 1 #include using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie..