작성일 :

문제 링크

24723번 - 녹색거탑

설명

높이 N인 녹색거탑에서 정상에서 바닥까지 내려오는 경우의 수를 구하는 문제입니다.


접근법

각 층마다 왼쪽 또는 오른쪽으로 내려갈 수 있으므로 선택지가 두 배씩 늘어납니다.

따라서 총 경우의 수는 2^N입니다.

비트 시프트로 1 « N을 계산하면 됩니다.



Code

C#

1
2
3
4
5
6
7
8
using System;

class Program {
  static void Main() {
    var n = int.Parse(Console.ReadLine()!);
    Console.WriteLine(1 << n);
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  cout << (1 << n) << "\n";

  return 0;
}