SHARE
TWEET

[CG]Count as I count

a guest Dec 3rd, 2019 84 in 18 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. import math
  3.  
  4. cache = dict()
  5. for i in range(1, 51):
  6.     for j in range(1, 51):
  7.         cache[(i, j)] = None
  8.  
  9. def card(nb_rounds, score):
  10.     if nb_rounds < 1 or score < 1:
  11.         return 0
  12.     if nb_rounds == 1:
  13.         if score == 1:
  14.             return 1
  15.         elif score < 13:
  16.             return 2
  17.         else:
  18.             return 0
  19.     if nb_rounds == score:
  20.         if nb_rounds < 13:
  21.             return 1
  22.         else:
  23.             return 0
  24.     if nb_rounds > score:
  25.         return 0
  26.     if score > 12 * nb_rounds:
  27.         return 0
  28.     if nb_rounds > 4:
  29.         return 0
  30.     res = 0
  31.     for i in range(1, nb_rounds):
  32.         for j in range(i, score - nb_rounds + i + 1):
  33.             if cache[(i, j)] is None:
  34.                 cache[(i, j)] = card(i, j)
  35.             if cache[(nb_rounds - i, score - j)] is None:
  36.                 cache[(nb_rounds - i, score - j)] = card(nb_rounds - i, score - j)
  37.             tmp = cache[(i, j)] * cache[(nb_rounds - i, score - j)]
  38.             print("card(i=" + str(i) + ", j=" + str(j) + ") * card(nb_rounds-i=" + str(nb_rounds-i) + ", score-j=" + str(score-j) + ")=" + str(tmp), file=sys.stderr)
  39.             res += tmp
  40.     print("card(" + str(nb_rounds) + ", " + str(score) + ")=" + str(res), file=sys.stderr)
  41.     return res
  42.  
  43.  
  44. # Auto-generated code below aims at helping you parse
  45. # the standard input according to the problem statement.
  46.  
  47. score = int(input())
  48. score = 50 - score
  49. #score = 3
  50. print(score, file=sys.stderr)
  51.  
  52. # Write an action using print
  53. # To debug: print("Debug messages...", file=sys.stderr)
  54.  
  55. res_score = card(1, score) + card(2, score) + card(3, score) + card(4, score)
  56. print(res_score)
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