S = { 1 , 2 , 3 , … , 1 9 , 2 0 }
How many subsets of three numbers each can be formed from the set above so that no two consecutive numbers are in the set?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
I prefer a straight (no trick) way of calculation: Total number of choosing 3 from 20 is: ( 3 2 0 ) . Out of them, we count the ones that have just 1 consecutive numbers:
− For the ones that have exactly one pair of consecutive numbers: The pair of consecutive numbers can be chosen from any 19 cases. Out of these 19 cases:
In 2 cases, the consecutive numbers are at the edge. In each such case, once the first 2 numbers are chosen, we have 17 numbers left to be the 3rd number, because 1 number out of the 18 numbers is neighboring with the consecutive numbers. That is: 1 7 ∗ 2
In other 17 cases, the 3rd number can be chosen from any number of the 16 eligible choices. That is: 1 7 ∗ 1 6
− For the ones that have two pair of consecutive numbers, we have 17 possible choices.
So the answer to the original question is: ( 3 2 0 ) − 1 7 ∗ 2 − 1 7 ∗ 1 6 − 1 7 = ( 3 2 0 ) − 1 7 ∗ 1 9 = 1 1 4 0 − 3 2 3 = 8 1 7
Where did I make a mistake?
Log in to reply
You said, "For the ones that have two pair of consecutive numbers, we have 17 possible choices."
The lowest number of the two pair can be from 1 to 18. (18, 19, 20) is the missing triple that gets you from 817 to 816!
Best wishes! ;^)
I still do not understand it. Please explain further.
Great trick. Your solution would be a bit easier to read if you spelled out that your way of picking triplets from 1 to 18 indeed does produce 1-1 all the legal ways to pick from 1 to 20. That is, that your transformation is bijective. It's easy to check, but the reader is left to wonder about it.
I misread the question. Didn't see the "of three numbers" part. No wonder I produced an answer of astronomical proportions lol
Impressive!
Nice solution
We will count the opposite, that is, the total number of sets such that there are at least 2 consecutive numbers:
Now these pairs of consecutive numbers can be ( 1 , 2 ) , ( 2 , 3 ) , … , ( 1 9 , 2 0 ) so we have 1 9 options and then to select the final number we have another 1 8 options. So 1 9 × 1 8 = 3 4 2 . However we counted twice the subsets where the three numbers are consecutive (i.e. the set ( 4 , 5 , 6 ) was counted when taking into account the pair ( 4 , 5 ) and the pair ( 5 , 6 ) ) so we need to subtract the number of subsets such that all the numbers are consecutive. These are ( 1 , 2 , 3 ) , ( 2 , 3 , 4 ) , … , ( 1 8 , 1 9 , 2 0 ) so there are 1 8 of them. So we have 3 4 2 − 1 8 = 3 2 4 subsets such that at least two numbers are consecutive.
Therefore the number of subsets such that no two numbers are consecutive is ( 3 2 0 ) − 3 2 4 = 8 1 6
Great explanation, Patrick! Nice use of principle of inclusion and exclusion (PIE) . I upvoted your solution (+1)
I did it in the same way.
Let a<b<c be the 3 numbers. Choose a first, then b, then c. When you choose a, a+1 can't be chosen for b or c. When you choose b, b+1 can't be chosen for c. Thus, we only have 18 numbers to choose from, every time we choose a triplet.
The number of ways to choose 3 objects from 18 is 18C3=816
Answer: 816
To me, this seems to be the clearest and most concise solution! Thank you for posting it! ;^)
Number of ways can be triplet formed with starting number 1 =
16+15+14+13+12+11+10+9+8+7+6+5+4+3+2+1 =136 ways
Number of ways can be triplet formed with starting number 2=
15+14+13+12+11+10+9+8+7+6+5+4+3+2+1 =120 ways
Number of ways can be triplet formed with starting number 3=
14+13+12+11+10+9+8+7+6+5+4+3+2+1 =105 ways
Number of ways can be triplet formed with starting number 4 =
13+12+11+10+9+8+7+6+5+4+3+2+1 =91 ways
Number of ways can be triplet formed with starting number 5 =
12+11+10+9+8+7+6+5+4+3+2+1 =78 ways
Number of ways can be triplet formed with starting number 6 =
11+10+9+8+7+6+5+4+3+2+1=66 ways
Number of ways can be triplet formed with starting number 7=
10+9+8+7+6+5+4+3+2+1 =55 ways
Number of ways can be triplet formed with starting number 8=
9+8+7+6+5+4+3+2+1 =45 ways
Number of ways can be triplet formed with starting number 9=
8+7+6+5+4+3+2+1 =36 ways
Number of ways can be triplet formed with starting number 10=
7+6+5+4+3+2+1 =28 ways
Number of ways can be triplet formed with starting number 11=
6+5+4+3+2+1=21 ways
Number of ways can be triplet formed with starting number 12=
5+4+3+2+1=15 ways
Number of ways can be triplet formed with starting number 13=
4+3+2+1=10 ways
Number of ways can be triplet formed with starting number 14=
3+2+1=6 ways
Number of ways can be triplet formed with starting number 15=
2+1=3 ways
Number of ways can be triplet formed with starting number 16 =
1 way
therefore total = 136 + 120 +..................... +1 = 816
There are so many ways to solve this problem. I ended up simply finding the sum of triangular numbers from the Pascal Triangle: S(n)=(1/6) n(n+1)(n+2). For n=16, s(16)= (1/6)(16)(17)(18)= 816. One can come up with n=16 by examining the patterns of possible sets. The largest element these sets can start with is 16, and that set will be {16, 18, 20}. So we can have only one set starting with 16, two sets starting with 15, etc.
I had worked out in the same manner as Pratham Shukla. However I find there are different ways of looking at it.
first place 20 box in a row and remove 3 boxes. now remaining 17 has 18 gap so select any 3 gap to put these consecutive number in 18 C 3 ways i.e. 816
Total possible sets is ( 20 C 3) = 1140 Sets wid exactly three elements consecutive = 18. Sets wid exactly two elements consecutive = 2 * 17 {for set (1,2,x) and (x,19,20)} + 17 * 19 = 324. Sets wid no consecutive elements = 1140 - 324 = 816
What's the use of the boxes if you didn't put anything in them. They feel empty, you know?
Let's consider all the invalid sets. All the sets that for sure are invalid definitely have the format: ( 1 , 2 , x ) , ( 2 , 3 , x ) , ( 3 , 4 , x ) . . . ( 1 9 , 2 0 , x ) Where x is some other arbitrary value from the original set. Analyzing our first invalid set from above, we see that there are 1 8 possibilities. Analyzing our next set, there must be 1 7 possibilities (Note: you have to exclude ( 2 , 3 , 1 ) as this was already counted; this pattern will be true for all of the rest of the sets--exclude the first number from the previous set). We see there is one template with 1 8 impossibilities and 1 8 templates of 1 7 impossibilities gives 1 8 + 1 8 ( 1 7 ) = 3 2 4 impossibilities. Given that there are 2 0 c h o o s e 3 possiblities, we do ( 2 0 c h o o s e 3 ) − 3 2 4 = 8 1 6 , giving us 8 1 6 valid sets.
Note: I'm new to latex, so apologies for the bad formatting. This solution is practically equivalent to Patrick's.
This is similar to the stars and bars problem, where counted objects are generalized into a string.
Here we have 2 0 objects, where 3 numbers that are not consecutive must be chosen.
If we write the stars as the other 1 7 objects and the 3 chosen objects as bars, we get a variant of the following:
∣ ∣ ∣ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
However, they cannot be consecutive, so we assume there is at least 1 star in between the bars. This lets us reduce the star count by 2 :
∣ ∣ ∣ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
We count the number of ways we can arrange this string, getting ( 3 1 8 ) , or 8 1 6 .
https://brilliant.org/wiki/integer-equations-star-and-bars/
C(20,3)-[(20-1)*(20-2)-18]
There are C(20,3) possible triplets. As for the forbidden triplets, for each (20-1) pairs of adjacent numbers there are (20-2) numbers remaining to complete the triplet. However, we're overcounting by 18, since a forbidden pair can be the first or last two numbers.
main()
{
int i,j,k,n,br=0;
cout << "Enter the number of set members: ";
cin >> n;
for (i=1; i<=n; i=i+1)
{
for (j=i+2; j<=n; j=j+1)
{
for (k=j+2; k<=n; k=k+1)
{
br=br+1;
cout << " " << br;
cout << " " << i;
cout << ", " << j;
cout << ", " << k;
cout <<endl;
}
}
}
}
Problem Loading...
Note Loading...
Set Loading...
Consider a triplet ( a , b , c ) where a , b and c are in ascending order, be transformed to ( a , b + 1 , c + 2 ) . This will eliminate the chances of occurrence of any consecutive numbers.
c + 2 ≤ 2 0 ⇒ c ≤ 1 8 .
Hence, we are free to choose any triplet ( a , b , c ) where a , b and c are in ascending order, from the first 1 8 numbers. These will be transformed as mentioned above to avoid two consecutive numbers in the triplet.
Number of ways to choose 3 numbers from these 1 8 numbers is ( 3 1 8 ) = 8 1 6