Computer Science, asked by gudherakesh, 1 year ago

python program for choosing balls​

Answers

Answered by brainlyuser1218
2

Answer:

input n=2

output: 3

the three ways are"*." ".*"&"**"where,'*'denote the choosen ball &'.'denotes the ball which did not get chosen

Answered by Anonymous
0

Program for choosing balls:

  • def countWays(a,b,c,las):

              if(a<0 or b<0 or c<or):

                     return 0;

              if(a==1 and b==0 and c==0 and las=0):

                     return 1;

              if(a==0 and b==1 and c==0 and las==0):

                     return 1;

               if(a==0 and b==0 and c==1 and las==0):

                     return 1;

              if(las==0):

                   return(countWays(a-1,b,c,1)+countWays(a-1,b,c,2));

              if(las==1):

                  return(countWays(a,b-1,c,1)+countWays(a,b-1,c,2));

              if(las==2):

                   return(countWays(a,b,c-1,1)+countWays(a,b,c-1,2));

          def countUtil(a,b,c):

               return(countWays(a,b,c,0)+countways(a,b,c,1)+countWays(a,b,c,2));

        #Driver code:

          a=1;

          b=2;

          c=3;

          print(countUtil(a,b,c));

  • There are 'a' balls of type A, 'b' balls of type B, 'c'balls of type C.
  • Input:

         a=1,b=1,c=0

       output: 2

        There are only two arrangements PQ and QP.

Similar questions