Algorithm, watermelon cut 10 knives, the maximum is how many pieces?

Source: Internet
Author: User
Just debut interview one to algorithm topic,
A watermelon, keep the shape unchanged, cut 10 knives up to how many pieces!

Reply content:

To help you search for an answer:
How many pieces can a watermelon cut into 100 knives? explain why.

The essence of your question is how many blocks of space can be divided by N planes. Let's look at the following three questions:
1) n points can be divided into as many segments as a straight line. The formula of the general term is recorded as a (n)
2) n lines can be divided into more than one area of the plane. The formula of the general term is B (n)
3) n A plane can divide the space by up to how many blocks. The general formula is written as C (n)
The first question, very simple, a (n) =n+1
Second question, assuming that there are already n straight lines in the plane, they divide the plane into the most area, then the n+1 line goes down, in order to guarantee the most area, then the line is required to intersect with the previous n lines, and the newly generated intersection does not coincide with the previous intersection. Obviously the first n+ The 1 lines and the previous n lines produce n intersections, which divide the n+1 line into A (n) segment, each of which divides the original region into two, so B (n+1) =b (n) +a (n), B (1) =2,a (n) =n+1 is easily obtained B (n) =[n (n+1) /2]+1
The third question is, in the same way, how many more blocks are added to the n+1 plane. The n planes of the front intersect with the n+1 plane, leaving n lines on the n+1 plane, where the nth intersection divides the n+1 plane into B (n) regions, and each region splits the original block in two, so C (n+1 ) =c (n) +b (n), C (1) =2,b (n) =[n (n+1)/2]+1 can be obtained in C (n) =[(n^3+5n)/6]+1
Tip: Use the following summation formula:
1+2+...+n=n (n+1)/2
1^2+2^2+...+n^2=n (n+1) (2n+1)/6
Bring the n=100 into C (n) c (100) =166751 If the knife is straight and is a 10-dimensional watermelon, the answer is 1024. Three-dimensional space, too? Cut with the knife blade, the number of blocks is more, but not easy to calculate. Those who say 1024, are in the middle of the move watermelon, or 10-dimensional space watermelon.
In the case of not moving the watermelon, the fourth knife how can not cut out 16 pieces. Do not understand the algorithm,
But I feel that the nth knife if all intersect with the former n-1 knife, this should be the case of the most block,
1+ (n (n+1))
56
Well, this seems to be a two-dimensional watermelon, 10 knives in each dimension can be cut out the maximum number of blocks:
1 D: 11
2 D: 56
3 D: 176
4 D: 386
5 D: 638
6 d: 848
7 D: 968
8 D: 1013
9 d: 1023
+: 1024
In general:
The number of blocks that the knife can cut out in the dimension space is the coefficient of the preceding two-item expansion and (no 0 for the item).
For example, 3 knives cut out 1+3+3=7 blocks in two-dimensional space. My first reaction was to use "greedy algorithm", not knowing right. Power of the two 10 times
1024 with the knife face a shot is perfect,
All right, joking, the next thing is the positive solution.
Answer the question of the main meaning is not clear, there is no limit whether you can move the watermelon in the process of cutting
1. Yes.
That's the answer. The big fairy has already said, 10^10=1024

2. No.
This time will need to primary School Olympiad (elementary school into the pit, the examination of Hangzhou City 34, but for the great god of the road is too bad)
0 Knives: 1 pieces
1 Knives: 2 pieces (nonsense)
2 Knives: 4 pieces
3 Knives: 8 pieces (cut into the shape of a second-order cube)
It's not surprising to see this, because it seems to happen 2^n? , this is because 3 of the knife can be guaranteed and each before the plane cut out of the small pieces and then cut into two pieces
4 Knives: 15 pieces (You can try it yourself, but you can find that it is not able to cut 16 pieces)
This is because each of the previous pieces cannot be divided into two. Then the numbers come out.
1,2,4,8,15
Cough, let's make a difference.
1,2,4,7
Eh, does this seem like there's no rule? Keep doing bad
Yes, this sequence is perfect, and the difference is 1.

Well, that's a recursive way to push.
1,2,4,8,15,26,42,64,93,130,176
1,2,4,7,11,16,22,29,37,46,56,67
1,2,3,4,5,6,7,8,9,10
1,1,1,1,1,1,1,1,1,1
(The following column serves as a tolerance for the above column, and then up) [the last column of 1111111 has been mended by a friend reminder]
So the answer should be 176 according to the question of the high ticket answer @ Brother Huang I wrote the python algorithm implementation.
The code is as follows:
def A(n):    return n+1def B(n):    if n==1:        return 2    return B(n-1)+A(n-1)def C(n):    if n==1:        return 2    return B(n-1)+C(n-1)print str(C(10))
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.