Home > Back-end >  To a great god for help in any way. Simply look at ideas and results
To a great god for help in any way. Simply look at ideas and results

Time:10-09

?????????? ? ??????????=2016
The ABCD EFGH and represent A 4 digits, including every letters (A - H) generation
Table 1-9 of which a number, the number of different letters represent different, please calculate the type on a
How many kinds of method? For example: 4613-2597=2016 is one of the solutions, beg god for help! The method is unlimited, thinking the answer

CodePudding user response:

The simplest is because is 4 digits, so the ABCD minimum is 3016, minimum EFHH is 1000, directly to iterate over come out to meet the conditions of the line,

CodePudding user response:

This is not just someone asked? Ideas like LS said
Lz refer to the following post
https://bbs.csdn.net/topics/396055683

CodePudding user response:

DFS directly line...

CodePudding user response:


The code is relatively simple, thinking is the DFS, is a permutation and combination
 # include 
using namespace std;
Int n, r;
Bool vis [30].
Int a, [30].
Void (pr) {
for(int i=1; i<=r; I++) {
CoutIf (I==4) {
Cout<& lt;" - ";
}
}
Cout<& lt;"=2016 "& lt; }
Void DFS (int x, int num) {
If (num> R) {
If (a * 1000 + [1] [2] a * 100 * 10 + a + a [3] [4], a [5] [6] * 100 * 1000 - a - a [7] [8] * 10 - a==2016) {
Pr ();
}
}
The else {
for(int i=1; i<=n; I++) {
If (! Vis [I]) {
Vis [I]=1;
A [x]=I;
DFS (x + 1, num + 1);
Vis [I]=0;
}
}
}
}
Int main () {
The scanf (" % d % d ", & amp; N, & amp; R);
DFS (1, 1);
return 0;
}

Enter 9 8
The results for the
9 8
4613-2597=2016
5714-3698=2016
5812-3796=2016
7314-5298=2016
7412-5396=2016
8513-6497=2016
  • Related