Skip to content

Commit a465d99

Browse files
Add files via upload
1 parent 2a0ab55 commit a465d99

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 13,
6+
"id": "246cfcd1",
7+
"metadata": {},
8+
"outputs": [
9+
{
10+
"name": "stdout",
11+
"output_type": "stream",
12+
"text": [
13+
"26\n",
14+
"[0, 0, 1, 1, 2, 1, 2, 3, 3, 2, 2, 3, 3, 4, 4, 2, 3, 4, 3, 4, 3, 4, 4, 5, 4, 2, 3]\n",
15+
"3\n"
16+
]
17+
}
18+
],
19+
"source": [
20+
"# 8-2 / 실전 문제 / 1로 만들기 written by me\n",
21+
"# DP -> 현재의 경우, 어떤 경우로 만들어 질 수 있는 경우인가를 분석해보기!\n",
22+
"\n",
23+
"n = int(input())\n",
24+
"\n",
25+
"array = [0]*(n+1)\n",
26+
"\n",
27+
"for i in range(2, n+1):\n",
28+
" array[i] = array[i-1]+1\n",
29+
" if i % 5 == 0:\n",
30+
" array[i] = min(array[i], array[i//5]+1)\n",
31+
" elif i % 3 == 0:\n",
32+
" array[i] = min(array[i], array[i//3]+1)\n",
33+
" elif i % 2 == 0:\n",
34+
" array[i] = min(array[i], array[i//2]+1)\n",
35+
" \n",
36+
"print(array)\n",
37+
"print(array[n])"
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": 12,
43+
"id": "393ea2b5",
44+
"metadata": {},
45+
"outputs": [
46+
{
47+
"name": "stdout",
48+
"output_type": "stream",
49+
"text": [
50+
"26\n",
51+
"3\n"
52+
]
53+
}
54+
],
55+
"source": [
56+
"# 8-2 / 실전 문제 / 1로 만들기 written by author\n",
57+
"\n",
58+
"x = int(input())\n",
59+
"\n",
60+
"d = [0]*30001\n",
61+
"\n",
62+
"for i in range(2, x+1):\n",
63+
" d[i] = d[i-1]+1\n",
64+
" \n",
65+
" if i % 2 == 0:\n",
66+
" d[i] = min(d[i], d[i//2]+1)\n",
67+
" if i % 3 == 0:\n",
68+
" d[i] = min(d[i], d[i//3]+1)\n",
69+
" if i % 5 == 0:\n",
70+
" d[i] = min(d[i], d[i//5]+1)\n",
71+
"\n",
72+
" \n",
73+
"print(d[x])"
74+
]
75+
}
76+
],
77+
"metadata": {
78+
"kernelspec": {
79+
"display_name": "Python 3 (ipykernel)",
80+
"language": "python",
81+
"name": "python3"
82+
},
83+
"language_info": {
84+
"codemirror_mode": {
85+
"name": "ipython",
86+
"version": 3
87+
},
88+
"file_extension": ".py",
89+
"mimetype": "text/x-python",
90+
"name": "python",
91+
"nbconvert_exporter": "python",
92+
"pygments_lexer": "ipython3",
93+
"version": "3.10.0"
94+
}
95+
},
96+
"nbformat": 4,
97+
"nbformat_minor": 5
98+
}

0 commit comments

Comments
 (0)