BC round 49 A untitled

Source: Internet
Author: User

I used to answer two questions, but the second question was hacked. When the two questions were answered, they ranked third in the room. It really scared me. To be honest, I did it seriously this time.

ResultEven though I only had one question, it seems that few people have had two questions. BC is such a pitfall, and it is always so difficult. What I have done these two times is recursive.Is also three recursion... A lot of people are doing nothing. I still have a question, as if I have always been a question... Continue to work

Do the questions carefully, do the questions carefully, and do the questions carefully (say the important things three times)

Ideas:

I did not sort this question. Because the number of layers increases progressively, we can find the least number of layers first. Each time we get the remainder of the number smaller than the current number, it will be OK, then let's continue to recursion its remainder until it is 0. At this time, we should mark a few times to end the future recursion, because we have found the minimum sequence that satisfies the condition...

Code:

<Span style = "font-family: Courier New; font-size: 18px;" >#include <stdio. h> # include <string. h> # include <stdlib. h> # include <limits. h> int N, Min, flag; int B [25]; void DFS (INT X, int ans) {If (x = 0) {flag = 1; if (ANS <min) min = ans; return;} For (INT I = 0; I <n; I ++) {If (B [I] <= X) {DFS (X % B [I], ANS + 1) ;}return ;}int main () {int I, T, A; scanf ("% d ", & T); While (t --) {memset (B, 0, sizeof (B); flag = 0; min = int_max; scanf ("% d ", & N, & A); for (I = 0; I <n; I ++) {scanf ("% d", & B [I]);} DFS (A, 0); If (flag = 1) {printf ("% d \ n", min);} elseprintf ("-1 \ n ");} return 0 ;}</span>

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

BC round 49 A untitled

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.