[InterviewBit] Intersecting Chords in a Circle

Intersecting Chords in a Circle

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
int Solution::chordCnt(int A) {
vector<long long> dp(max(3,A + 1));
dp[0] = dp[1] = 1;
dp[2] = 2;
long long mod = 1e9 + 7;
for(int i = 3; i <= A; i++) {
for(int j = 0; j < i; j++) {
dp[i] = (dp[i] + dp[i - j - 1] * dp[j] % mod) % mod;
}
}

return dp[A];
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/10/13/PS/interviewbit/intersecting-chords-in-a-circle/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.