File tree Expand file tree Collapse file tree 2 files changed +104
-0
lines changed Expand file tree Collapse file tree 2 files changed +104
-0
lines changed Original file line number Diff line number Diff line change 1+ /* *
2+ * @file 16953.cpp
3+ * @brief A -> B
4+ * @author Sam Kim (samkim2626@gmail.com)
5+ */
6+ #include < iostream>
7+
8+ using namespace std ;
9+
10+ int main ()
11+ {
12+ ios_base::sync_with_stdio (false );
13+ cin.tie (nullptr );
14+
15+ int a, b;
16+ cin >> a >> b;
17+
18+ int cnt = 0 ;
19+ while (1 )
20+ {
21+ if (a > b)
22+ {
23+ cout << -1 << ' \n ' ;
24+ break ;
25+ }
26+ if (a == b)
27+ {
28+ cout << cnt + 1 << ' \n ' ;
29+ break ;
30+ }
31+
32+ if (b % 10 == 1 )
33+ {
34+ b /= 10 ;
35+ }
36+ else if (b % 2 == 0 )
37+ {
38+ b /= 2 ;
39+ }
40+ else
41+ {
42+ cout << -1 << ' \n ' ;
43+ break ;
44+ }
45+ cnt++;
46+ }
47+
48+ return 0 ;
49+ }
Original file line number Diff line number Diff line change 1+ /* *
2+ * @file 5557.cpp
3+ * @brief 1학년
4+ * @author Sam Kim (samkim2626@gmail.com)
5+ *
6+ * 못 풀어서 솔루션 참고. 문제 풀이, 접근 방법 다시 확인
7+ *
8+ * 2차원배열
9+ * dp[i][j] : i번째 수까지 계산했을 때 j값을 만드는 올바른 등식의 수
10+ * 1. j-num[i] >= 0 / 2. j+num[i] <= 20
11+ *
12+ * dp테이블 int -> long long (2^63-1)
13+ */
14+ #include < iostream>
15+
16+ using namespace std ;
17+
18+ int num[101 ];
19+ long long dp[101 ][21 ];
20+
21+ int main ()
22+ {
23+ ios_base::sync_with_stdio (false );
24+ cin.tie (nullptr );
25+
26+ int n;
27+ cin >> n;
28+ for (int i = 1 ; i <= n; i++)
29+ {
30+ cin >> num[i];
31+ }
32+
33+ dp[1 ][num[1 ]] = 1 ; // 첫 번째 수까지 경우의 수 초기화
34+ for (int i = 2 ; i <= n; i++)
35+ {
36+ for (int j = 0 ; j <= 20 ; j++)
37+ {
38+ if (dp[i - 1 ][j] >= 0 )
39+ {
40+ if (j - num[i] >= 0 )
41+ {
42+ dp[i][j - num[i]] += dp[i - 1 ][j];
43+ }
44+ if (j + num[i] <= 20 )
45+ {
46+ dp[i][j + num[i]] += dp[i - 1 ][j];
47+ }
48+ }
49+ }
50+ }
51+
52+ cout << dp[n - 1 ][num[n]] << ' \n ' ;
53+
54+ return 0 ;
55+ }
You can’t perform that action at this time.
0 commit comments