SHARE
TWEET

Integer Partitioning [Range]

keverman Jan 20th, 2018 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. long long intPart(int n, long long  *P = P)
  2. {
  3.     if(n == 0) return (P[0] = 1);
  4.     if(n == 1) return (P[1] = 1);
  5.  
  6.     if(!P[n])
  7.         for(int k = 1; (k * (3 * k - 1)) / 2 <= n; k++)
  8.             for(int i = 1; i < 4 && k * (3 * k + i - 2) / 2 <= n; i += 2)
  9.                 P[n] += ((k & 1 ? 1: -1) * intPart(n - (k * (3 * k + i - 2) / 2), P));
  10.  
  11.     return P[n];
  12. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top