diff --git a/TangDou/LanQiaoBei/LanQiao15STEMA20231217/5.cpp b/TangDou/LanQiaoBei/LanQiao15STEMA20231217/5.cpp new file mode 100644 index 0000000..8bae870 --- /dev/null +++ b/TangDou/LanQiaoBei/LanQiao15STEMA20231217/5.cpp @@ -0,0 +1,14 @@ +#include +using namespace std; +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; +} \ No newline at end of file diff --git a/TangDou/LanQiaoBei/LanQiao15STEMA20231217/5.md b/TangDou/LanQiaoBei/LanQiao15STEMA20231217/5.md new file mode 100644 index 0000000..a7f5536 --- /dev/null +++ b/TangDou/LanQiaoBei/LanQiao15STEMA20231217/5.md @@ -0,0 +1,36 @@ +```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