Created
April 15, 2020 10:23
-
-
Save niklasjang/bb5e29ed4171e49135f3f4062f3d7779 to your computer and use it in GitHub Desktop.
[PS][DP]/[BOJ][9095][1, 2, 3 더하기]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int dp[11]; | |
| int main(void) { | |
| dp[1] = 1; | |
| dp[2] = 2; | |
| dp[3] = 4; | |
| for (int i = 4; i <= 10; i++) { | |
| dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3]; | |
| } | |
| int n=0,m=0; | |
| cin >> n; | |
| while (n--) { | |
| cin >> m; | |
| cout << dp[m] << "\n"; | |
| } | |
| return 0; | |
| } |
Author
Author
//int형 return 값을 갖는 recur함수 풀이
#include <iostream>
using namespace std;
int n = 0;
int arr[100] = { 0 };
int recur(int sum) {
int ret = 0;
if (sum == 0) return 1;
for (int i = 1; i <= 3; i++) {
if (i <= sum) {
ret += recur(sum - i);
}
}
return ret;
}
int main(void) {
int t = 0;
cin >> t;
while (t--) {
cin >> n;
cout << recur(n) << "\n";
}
return 0;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//모든 경우의 수를 하나씩 세는 방법