Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- private static final long mod = 1000000007L;
- public int chordCnt(int A) {
- long[] dp = new long[2001];
- Arrays.fill(dp, -1);
- dp[0] = 1;
- dp[2] = 1;
- int ans = (int)(findPossible(dp, 2*A)%(mod));
- return ans;
- }
- private static long findPossible(long[] dp, int p) {
- if(dp[p] != -1) {
- return dp[p];
- }
- long sum = 0;
- for(int i = 1; i <= p - 1; i=i+2) {
- long a1 = findPossible(dp, i-1);
- long a2 = findPossible(dp, p-1-i);
- long possible = a1 * a2;
- sum += possible;
- }
- dp[p] = sum;
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement