37 lines
684 B
Markdown
37 lines
684 B
Markdown
```cpp {.line-numbers}
|
|
int func( int x, int y, int z )
|
|
{
|
|
if( x == 1 || y == 1 || z == 1 ) return 1;
|
|
if( x < y && x < z )
|
|
return func( x, y - 1, z ) + func( x, y, z - 1 );
|
|
if( y < x && y < z )
|
|
return func( x - 1, y, z ) + func( x, y, z - 1 );
|
|
return func( x - 1, y, z ) + func( x, y - 1, z );
|
|
}
|
|
int main()
|
|
{
|
|
cout << func( 3, 3, 2 );
|
|
return 0;
|
|
}
|
|
```
|
|
将$func()$简写成$f()$
|
|
|
|
人脑模拟电脑
|
|
|
|
$f(3,3,2)=f(2,3,2)+f(3,2,2)$
|
|
|
|
其中
|
|
$f(2,3,2)=f(1,3,2)+f(2,2,2)$ ①
|
|
$f(3,2,2)=f(2,2,2)+f(3,1,2)$ ②
|
|
|
|
最终$res=①+②$
|
|
|
|
$f(1,3,2)=1$
|
|
$f(2,2,2)=f(1,2,2)+f(2,1,2)=1+1=2$
|
|
|
|
$\therefore$ ①=3
|
|
|
|
②=3
|
|
|
|
①+②=6
|