IT company interview questions collected and sorted-C-related algorithms (targeted for 10 times, for 90, how many algorithms, difficult to death)

Source: Internet
Author: User

I saw an interview question today. It generally means that a person scored 90 targets for 10 times and scored 0-10. How many combinations are there?

The program is very complex, so I will not post it, because this value is very special, it is 100 in all, only hit 90, so 10 are not in the middle. The results are the same.

If a total of 90 hits is the same as a total of 10 hits, the number of results should be the same. Then, we can calculate that the total number cannot be reached.

First case: the sum of a total of 10

We write a mathematical formula

X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + x9 + x10 = 10; [X1 --- x10 are non-negative integers] the range of X is 0 <= x <= 10 [this 10 is not just the value of the formula 10. The key is to do this, the maximum value of the target score is the same. This is the key to solving the problem]

So we use the replacement method [replacement method is a common method in high school, so I won't be able to do it], set T> = 1. T-1 = x then written as below

T1 + T2 + T3 + T4 + T5 + T6 + T7 + T8 + T9 + t10-10 = 10;

T1 + T2 + T3 + T4 + T5 + T6 + T7 + T8 + T9 + t10 = 20;

Well, we will use the partition method [the partition method won't be Baidu]. For the partition method, the T range is [1 <= T <= 11 ], then, nine baffle plates are inserted in (20-1) spaces. The result is obvious. The result is C (). [This is the formula for permutation and combination. This is written because it cannot be obtained up or down]

Let's go to the previous figure.

The result is 92378.

Case 2: sum of total hits: 90

The first method is the replacement method and the partition method.

Now we can use this method to find the problem. t1 + T2 + T3 + T4 + T5 + T6 + T7 + T8 + T9 + t10 = 100;

The result is C (). It is obvious that this number is large and the result is not this value. So where are our mistakes?

The error is in the range of [T]. The first method is provided that the minimum value of the target is 0 and the maximum value is 10. After replacement, the minimum value is 1 and the maximum value is 11.

However, if the range of [T] In the second method is 1-, the result will certainly be incorrect. The following results may appear:

If the result is, X is 0, 0, 0, 0, 0, 0, 0, is there a 90-ring maximum target? No. The target range is [, 10]

So we can't think about this directly. We need to think about the problem.

Well, thank you for reading the ending question. It was my opinion on the interview company's subject and I thought it out without programming. I hope you can correct me more.

How deep is the skill of mathematics, how far can programmers go? Wang yuchao, come on !!!

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.