We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents c4f0571 + 274c907 commit 1baacbfCopy full SHA for 1baacbf
package/Other/GetCattle.php
@@ -21,19 +21,18 @@
21
function getCattle($n)
22
{
23
static $num = 1;
24
- for ($i =1; $i<=$n;$i++){
25
- if( $i == 20) break;
26
- if($i >= 4 && $i <15){
27
- if($i % 4 == 0 ){
28
- getCattle($n - $i);
29
- $num++;
30
- }
31
+ for ($i = 1; $i <= $n; $i++) {
+ if ($i == 20) {
+ $num--; //死亡需减一
+ } else if ($i >= 4 && $i < 15) {
+ $num++; //生小母牛(这里有小母牛)
+ getCattle($n - $i); //小母牛生小母牛(这里不包含小母牛)
32
}
33
34
return $num;
35
36
-echo '牛年共有:'.getCattle(10);
+
+echo '牛年共有:' . getCattle(10);
37
38
/*
39
123456789
0 commit comments