The function f : Z × Z → N is defined as follows: f ( n , m ) = ⎩ ⎪ ⎨ ⎪ ⎧ 0 1 f ( n − 1 , m − 1 ) + 2 f ( n − 1 , m ) n < 0 or m < 0 n = 0 and m = 0 elsewhere
What is the value of f ( 3 2 , 1 6 ) ?
Side note: The function f ( n , m ) returns the number of m -faces in an n -hypercube .
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The function
f
(
n
,
m
)
can be calculated recursively. However, since there are repeated function calls with the same parameters, the intermediate results should be buffered in a data structure, so that it does not come to the stack overflow. This role is taken over by the dictionary
memo
. Here is the complete listing of my Python program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
f ( n$_$ , m$_$ ) := 0 /; n < 0 ∨ n < 0
f ( n$_$ , m$_$ ) := 1 /; n = 0 ∧ m = 0
f ( n$_$ , m$_$ ) := f ( n , m ) = f ( n − 1 , m − 1 ) + 2 f ( n − 1 , m )
f ( 3 2 , 1 6 ) ⟹ 3 9 3 9 2 4 0 4 4 3 9 0 4 0
Memoization occurs in the third line to reduce the computation time.
Here is one of the ways to solve it using DP;
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
39392404439040
Problem Loading...
Note Loading...
Set Loading...
The number of m -faces on a n -hypercube can be defined as f ( n , m ) = 2 n − m ( m n ) (see inductive proof below). Therefore, the number of 1 6 -faces inside a 3 2 -dimensional hypercube would be f ( 3 2 , 1 6 ) = 2 3 2 − 1 6 ( 1 6 3 2 ) = 3 9 3 9 2 4 0 4 4 3 9 0 4 0
Inductive Proof:
Assuming f ( n , m ) = 2 n − m ( m n ) is true, it can be shown that f ( n + 1 , m ) = f ( n , m − 1 ) + 2 f ( n , m ) = 2 n + 1 − m ( m n + 1 ) as follows:
f ( n + 1 , m )
= f ( n , m − 1 ) + 2 f ( n , m )
= 2 n − ( m − 1 ) ( m − 1 n ) + 2 ⋅ 2 n − m ( m n )
= 2 n + 1 − m ( n − ( m − 1 ) ) ! ( m − 1 ) ! n ! + 2 n + 1 − m ( n − m ) ! m ! n !
= 2 n + 1 − m [ ( n + 1 − m ) ! ( m − 1 ) ! n ! + ( n − m ) ! m ! n ! ]
= 2 n + 1 − m [ ( n + 1 − m ) ! m ( m − 1 ) ! n ! m + ( n + 1 − m ) ( n − m ) ! m ! n ! ( n + 1 − m ) ]
= 2 n + 1 − m [ ( n + 1 − m ) ! m ! n ! m + ( n + 1 − m ) ! m ! n ! ( n + 1 − m ) ]
= 2 n + 1 − m ( n + 1 − m ) ! m ! n ! ( m + n + 1 − m )
= 2 n + 1 − m ( n + 1 − m ) ! m ! n ! ( n + 1 )
= 2 n + 1 − m ( n + 1 − m ) ! m ! ( n + 1 ) !
= 2 n + 1 − m ( m n + 1 )
Therefore, by inductive proof the number of of m -faces on a n -hypercube can be defined as f ( n , m ) = 2 n − m ( m n ) .