알고리즘 문제/BOJ
4811번 알약
parkit
2019. 1. 7. 16:33
728x90
반응형
https://www.acmicpc.net/problem/4811
개인적으로 별로좋은 문제는 아니라고 생각한다.
다른 분의 코드를 참고하였다.
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #include <iostream> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> #include <map> using namespace std; long long a[31][31] = { 0, }; long long search(int w, int h) { if (w < 0) return 0; if (a[w][h] > 0) return a[w][h]; if (w == 0 && h == 0) return 1; if (w > 0) a[w][h] += search(w - 1, h + 1); if (h > 0) a[w][h] += search(w, h - 1); return a[w][h]; } int main(void) { int N = 0; while (1) { scanf("%d", &N); if (N == 0) break; cout << search(N, 0) << '\n'; } return 0; } | cs |
728x90
반응형