{"trustable":true,"prependHtml":"\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eWe all love recursion! Don\u0027t we?\u003cbr\u003e\n \u003cbr\u003e\n Consider a three-parameter recursive function w(a, b, c):\u003cbr\u003e\n \u003cbr\u003e\n if a \u0026lt;\u003d 0 or b \u0026lt;\u003d 0 or c \u0026lt;\u003d 0, then w(a, b, c) returns:\u003cbr\u003e\n 1\u003cbr\u003e\n \u003cbr\u003e\n if a \u0026gt; 20 or b \u0026gt; 20 or c \u0026gt; 20, then w(a, b, c) returns:\u003cbr\u003e\n w(20, 20, 20)\u003cbr\u003e\n \u003cbr\u003e\n if a \u0026lt; b and b \u0026lt; c, then w(a, b, c) returns:\u003cbr\u003e\n w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c)\u003cbr\u003e\n \u003cbr\u003e\n otherwise it returns:\u003cbr\u003e\n w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1)\u003cbr\u003e\n \u003cbr\u003e\n This is an easy function to implement. The problem is, if implemented directly, \n for moderate values of a, b and c (for example, a \u003d 15, b \u003d 15, c \u003d 15), the \n program takes hours to run because of the massive recursion.\u003c/p\u003e\n\u003cp\u003e\u003cbr\u003e\n \u003cb\u003eInput\u003c/b\u003e\u003cbr\u003e\n \u003cbr\u003e\n The input for your program will be a series of integer triples, one per line, \n until the end-of-file flag of -1 -1 -1. Using the above technique, you are to \n calculate w(a, b, c) efficiently and print the result. For example:\u003cbr\u003e\n \u003cbr\u003e\n 1 1 1\u003cbr\u003e\n 2 2 2\u003cbr\u003e\n 10 4 6\u003cbr\u003e\n 50 50 50\u003cbr\u003e\n -1 7 18\u003cbr\u003e\n -1 -1 -1 \u003c/p\u003e\n\u003cp\u003e\u003cbr\u003e\n \u003cb\u003eOutput\u003c/b\u003e\u003cbr\u003e\n \u003cbr\u003e\n Print the value for w(a,b,c) for each triple, like this:\u003cbr\u003e\n \u003cbr\u003e\n w(1, 1, 1) \u003d 2\u003cbr\u003e\n w(2, 2, 2) \u003d 4\u003cbr\u003e\n w(10, 4, 6) \u003d 523\u003cbr\u003e\n w(50, 50, 50) \u003d 1048576\u003cbr\u003e\n w(-1, 7, 18) \u003d 1\u003cbr\u003e\n\u003c/p\u003e"}}]}