[Codewars] Explosive Sum

Explosive Sum

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using ull = unsigned long long;

ull dp[1000][1000];
ull helper(unsigned int n, unsigned int ma) {
if(n == 0) return 1;
ull& res = dp[n][ma];
if(res) return res - 1;
res = 1;
for(unsigned int i = 1; i <= ma and i <= n; i++) {
res += helper(n-i,i);
}
return res - 1;
}
ull exp_sum(unsigned int n) {
return helper(n,n);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/05/01/PS/Codewars/explosive-sum/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.