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