Advertisement
krot

разложение на слагаемые

Sep 12th, 2020
2,426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.27 KB | None | 0 0
  1. <?
  2. $n=5;
  3. r($n);
  4. function r($left,$min=0,$i=0){
  5.     global $a,$n;
  6.     if($left<0||$min==$n)return;
  7.    
  8.     $a[$i]=$min;
  9.    
  10.     if($min!=0){
  11.         r($left-$min,$min,$i+1);
  12.     }
  13.     r($left-1,$min+1,$i);
  14.     if($left==0){
  15.         for($j=0;$j<=$i;++$j){
  16.             echo $a[$j].($j!=$i?'+':PHP_EOL);
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement