1,481 views
2 votes
2 votes
how many number are possible of 4 digits whose sum is 12.

3 Answers

Best answer
6 votes
6 votes
The solution can be formulated as : x1+x2+x3+x4 = 12, which has solution 12+4-1C 4-1 = 455(Star and bar problem).

It will also include cases where x1 , x2 , x3 , x4 will take 10 , 11 , 12 values which cannot be the values of any digit.

So we have to remove all those cases.

Now, secondly when 1st digit becomes 0 then the number will not be of 4 digits. So we have to remove those cases.

In that case, put x1 = 0 and find the solution for x2+x3+x4 = 12 => 14C2 = 91(It will also remove all cases where x1 = 0 and x2,x3,x4 >= 0 )

Now we have to remove that case where x1 takes 10 , 11 , 12.

When x1 = 10, x2 +x3+x4 = 2 which gives 4C2 = 6.

When x1 = 11, x2+x3+x4 = 1 which gives 3C2 = 3.

When x1 = 12, x2+x3+x4 = 0 which gives 2C2 = 1.

Now, cases when x2,x3,x4 >= 10  we will count cases for x2 only , same will be applied on x3 and x4 also

x2 = 10 , x1 = 1 , then  x3 + x4 = 1  which gives 2C1 = 2.

x2 = 10 , x1 = 2 , then  x3 + x4 = 0 which gives 1C1 = 1.

x2 = 11 , x1 = 1 , then  x3 + x4 = 0  which gives 1C1 =1.

total ways = 3 * ( 2 + 1 + 1 ) = 12 , same for x3 and x4.

Now total ways :  15C3 - 14C2 -  ( 6 + 3 + 1 ) - 12 =  455 - 91 - 22 = 342.
selected by
7 votes
7 votes

The problem can be formulated mathematically as no of non negative integral solutions of:

X1 + X2 + X3 + X4  =  12 

where 1 <= X1 <= 9 , 0 <= X2,X3,X4 <= 9

So it is given by coefficient of x12 in (x + x2.........+ x9) . (1 + x + x2 ............. + x9)3 

 ==> coefficient of x12 in  x( 1 + x .........+ x8) .(1 + x ........x9)3

 ==>  coefficient of x11 in  ( 1 + x .........+ x8) .(1 + x ........x9)3

 ==>  coefficient of x11 in   (1 - x9) . (1 - x10)3 (1 - x) -4          [From sum of G.P. formula]

 ==>  coefficient of x11 in   (1 - x9) . ( 1 - 3x10 + 3x20  -  x30) (1 - x)-4

So picking up the relevant terms only we need to find coefficient of x11 in  (1 - x)-4  , -x9 (1 - x)-4 and -3x10 (1 - x)-4..We know :

Coefficient of xr  in (1 - x)-n   =  n-1+r Cr

So for 1st term , putting r = 11 , n = 4 , we have ,

Coefficient of  x11 in  (1 - x)-4  =   4-1+11 C11

                                            =   (14 * 13 * 12) / 6

                                            =   364

Coefficient of  x11 in -x9 (1 - x)-4    =   - (Coefficient of  x2  in   (1 - x)-4   )

                                                  =   - (4 - 1 + 2 C2 )

                                                  =   - 10

Coefficient of  x11 in  -3x10 (1 - x)-4    =   - 12

Hence number of such 4 digit numbers whose sum of digits is 12  =  364 - 10 - 12

                                                                                                =  342

Hence 342 is the correct answer..

3 votes
3 votes
Make a table of 4 * 12

dp[4][12]  where  dp[i][j] = total numbers formed using only starting i digits which have sum = j.

Over final answer is dp[4][12]

           int n = 4;
           int sum = 12;

     int dp[n + 1][sum + 1];
            memset(dp , 0 , sizeof dp);

             for(int i = 1 ; i <= 9 ; ++i )
             dp[1][i] = 1;

             for(int i = 2 ; i <= n ; ++i ){

               for(int j = 0 ; j < 10 ; ++j ) {              // we can fill our ith place with 0 <= digit <= 9.
                    for(int k = 0 ; j + k <= sum ; ++k )    
                   dp[i][j + k] += dp[i - 1][k];

               }

             }

      dp[n][sum] = 342.

0 1 1 1 1 1 1 1 1 1 0 0 0
0 1 2 3 4 5 6 7 8 9 9 8 7
0 1 3 6 10 15 21 28 36 45 54 61 66
0 1 4 10 20 35 56 84 120 165 219 279 342

Dynamic Programming.

Related questions

1 votes
1 votes
0 answers
1
Pineapple asked Mar 23, 2023
279 views
How many ways are there to distribute five distinguishable objects into three indistinguishable boxes?
3 votes
3 votes
1 answer
2
Mk Utkarsh asked Mar 7, 2019
554 views
Find the generating function for the sequence $\left \{ a_n \right \} where $$a_n = \Large \binom{10}{n+1} $ for n = 0,1,2,….Sol. $\Large \binom{10}{1} + \binom{10}{2...
1 votes
1 votes
1 answer
3
Lakshman Bhaiya asked Oct 24, 2018
551 views
A number of ways we can arrange letters of the word " TESTBOOK " such that E always comes between O's is ___________
0 votes
0 votes
1 answer
4
rtalwar asked Oct 13, 2018
2,440 views
How many bit strings with length not exceeding $n$ ,where n is a positive integer ,consist entirely of $1's?$