-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-acm.cpp
58 lines (52 loc) · 821 Bytes
/
4-acm.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <windows.h>
int fivo[100];
int top = -1;
long long fibo(int n) // 동적프로그래밍 방식
{
if (n <= 2) {
return 1;
}
else if(n > top) //쓰레기값일때
{
fivo[n] = fibo(n - 1) + fibo(n - 2);
top = n;
}
return fivo[n];
}
long long find_max_fibo(int n) {
for (int i = 3; i < 100; i++) {
if (fivo[i] > n) {
return fibo(i - 1);
}
}
}
void find_fibos(int n) {
if (n == 1) {
printf("1 ");
}
else {
long long f = find_max_fibo(n);
if (f == n) {
printf("%lld ", f);
}
if (n - f > 0) {
n -= f;
find_fibos(n);
printf("%lld ", f);
}
}
}
int main() {
printf("2071360 이종범\n");
int T, n;
scanf("%d", &T);
fibo(80);
for (int i = 0; i < T; i++) {
scanf("%d", &n);
find_fibos(n);
printf("\n");
}
Sleep(10000);
}