Advertisement
Guest User

Untitled

a guest
Aug 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. public class Solution {
  2.     private static final long mod = 1000000007L;
  3.     public int chordCnt(int A) {
  4.         long[] dp = new long[2001];
  5.         Arrays.fill(dp, -1);
  6.         dp[0] = 1;
  7.         dp[2] = 1;
  8.         int ans = (int)(findPossible(dp, 2*A)%(mod));
  9.         return ans;
  10.     }
  11.    
  12.     private static long findPossible(long[] dp, int p) {
  13.         if(dp[p] != -1) {
  14.             return dp[p];
  15.         }
  16.         long sum = 0;
  17.         for(int i = 1; i <= p - 1; i=i+2) {
  18.             long a1 = findPossible(dp, i-1);
  19.             long a2 = findPossible(dp, p-1-i);
  20.             long possible = a1 * a2;
  21.             sum += possible;
  22.         }
  23.         dp[p] = sum;
  24.         return sum;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement