diff options
| author | deadmarshal <adeadmarshal@gmail.com> | 2023-01-28 20:44:13 +0330 |
|---|---|---|
| committer | deadmarshal <adeadmarshal@gmail.com> | 2023-01-28 20:44:13 +0330 |
| commit | 79df3f502658e9e7622ce49faa32ee703d936f67 (patch) | |
| tree | fc3a7c9a5c0f8ef69b77122b254f62e3578effcf /challenge-201/deadmarshal/cpp/ch-2.cpp | |
| parent | 27b88f614b9bb53872ef0da19a56087505836db0 (diff) | |
| download | perlweeklychallenge-club-79df3f502658e9e7622ce49faa32ee703d936f67.tar.gz perlweeklychallenge-club-79df3f502658e9e7622ce49faa32ee703d936f67.tar.bz2 perlweeklychallenge-club-79df3f502658e9e7622ce49faa32ee703d936f67.zip | |
TWC201
Diffstat (limited to 'challenge-201/deadmarshal/cpp/ch-2.cpp')
| -rw-r--r-- | challenge-201/deadmarshal/cpp/ch-2.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-201/deadmarshal/cpp/ch-2.cpp b/challenge-201/deadmarshal/cpp/ch-2.cpp new file mode 100644 index 0000000000..d05bc157e5 --- /dev/null +++ b/challenge-201/deadmarshal/cpp/ch-2.cpp @@ -0,0 +1,31 @@ +#include<iostream> + +#define N 5 +static int count{}; + +void find_combinations(int *arr, + int index, + int num, + int reduced_num) +{ + if(reduced_num < 0) return; + if(reduced_num == 0) + { + count++; + return; + } + int prev = index == 0 ? 1 : arr[index-1]; + for(int i = prev; i <= num; ++i) + { + arr[index] = i; + find_combinations(arr,index+1,num,reduced_num-i); + } +} + +int main() +{ + int arr[N]; + find_combinations(arr,0,N,N); + std::cout << count << '\n'; +} + |
