#DevStudy/문제풀이
[Baekjoon] 9625 - BABBA
검은_백조
2016. 10. 13. 18:34
https://www.acmicpc.net/problem/9625
피보나치 문제.
A
B
BA = B + A
BAB = BA + B
BABBA = BAB + BA
....
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 | #include <stdio.h> #include <stdlib.h> #include <memory.h> #define MAX 50 int countA[MAX]; int countB[MAX]; int main() { int count; scanf("%d", &count); memset(countA, 0, sizeof(int) * MAX); memset(countB, 0, sizeof(int) * MAX); countA[2] = 1; countB[1] = 1; countB[2] = 1; for(int i = 3; i <= count; i++){ countA[i] = countA[i-2] + countA[i-1]; countB[i] = countB[i-2] + countB[i-1]; } printf("%d %d\n", countA[count], countB[count]); return 0; } | cs |