20. Check
The basic idea of the checking process is to find the number of each number in the "and", and then compare it with the number combination of the "and, if the two are the same, "and" is the number of flowers.
For example, you can obtain the 3rd Power Sum of these three numbers from a 5, 3, and 1, and the sum is 5 ^ 3 + 3 ^ 3 + 1 ^ 3 = 153, and 153 happens to be composed of three numbers: 5, 3, and 1. Then we can conclude that 153 is the number of flowers.
On the contrary, a sum of five, three, and two can obtain the 3rd power of these three numbers, 5 ^ 3 + 3 ^ 3 + 2 ^ 3 = 160,160 contains a 6, a 1, and a 0, which is inconsistent with the combination of the three numbers (160, 2) obtained from, this indicates that 160 is not the number of flowers.
This algorithm first records the number of each number that calculates the sum of the N power of the number.
Record the number of numbers
Define this data type in "2 _ exhaustive. c"
Typedef unsigned int SHUZI_GESHU [JINZHI];
// SHUZI_GESHU [d] Number of numbers stored in d
Define local variables of this type in xunhuan (), which should be static
Static SHUZI_GESHU sz_gs;
Record the number of numbers in the recursion process, and test
Static void xunhuan (const int gssx/* Number Limit */, const int sz/* about which number */, DASHU (* p_hang) [WEISHU + 1]/* point to a row of Data */) {static DASHU he ={{ 0 }}; // static DASHU he; // = 0 to be completed DASHU he _ = he; // The value before record accumulation static SHUZI_GESHU sz_gs; if (sz> 0) {int I; for (I = 0; I <= gssx; I ++) {sz_gs [sz] = I; // records the number of numbers ds_jiaru (& he, * p_hang + I ); xunhuan (gssx-I, sz-1, p_hang + 1); he = he _; // Restore original value} else {sz_gs [sz] = gssx; // number of records # ifdef CESHI {int I; for (I = 0; I <JINZHI; I ++) {printf ("% d * % d", sz_gs [I], I);} putchar ();} # endif // check <=> record result} passed the test.
Then, write the checking code in xunhuan () to check whether the number in "and" appears the same as the number in sz_gs.
Xunhuan ()
{
......
If (matching (& sz_gs, & he) = Yes) {// check
// <=> Record the result
}
}
Matching (& sz_gs, & and)
{
Int and the number of numbers [JINZHI];
If (more than W bits (and) = Yes | less than W bits (and) = Yes) {// # include "3 _ large number. h"
Return no;
}
The number of numbers in the sum (& and the number of numbers in the middle, & and); // # include "3 _ large number. h"
If (memcmp (and the number of numbers in the middle, sz_gs, sizeof, and number of numbers in the middle) = 0) {// # include <string. h>
Return yes;
}
Return no;
}
This Code involves a lot of questions about whether to answer yes or no. Because I hate to bother thinking about this problem with 0 or 1 when writing code, I added such a file to the project.
/* Common. h */# ifndef CHANGYONG_H # define CHANGYONG_H typedef enum {SHI, FOU} SF; # endif // CHANGYONG_H and in "2 _ poor lifting respectively. h "," 3 _ large number. h "added
# Include "common. h"
Now, "2 _ example. h" has evolved
/* 2 _ example. h */# ifndef QIONGJU_H # define QIONGJU_H/*************************** type definition ** * ***********************/# include "3 _ large numbers. h "# include" commonly used. h "/************************** function prototype ********* * ***************/extern void qiongju (void ); # include <stdlib. h> // malloc () # endif // QIONGJU_H
2 _ example c evolved
/* 2 _ example. c */# include "2 _ example. h "# include" 0 _ problem. h "typedef unsigned int SHUZI_GESHU [JINZHI]; // SHUZI_GESHU [d] Number of stored numbers typedef dashu shujubiao [JINZHI-1] [WEISHU + 1]; // 0 * (JINZHI-1) ^ N 1 * (JINZHI-1) ^ N ...... WEISHU * (JINZHI-1) ^ N // 0 * (JINZHI-2) ^ N 1 * (JINZHI-2) ^ N ...... WEISHU * (JINZHI-1) ^ N //...... // 0 * (1) ^ N 1 * (1) ^ N ...... WEISHU * (1) ^ Nstatic void xunhuan (const int, const int, DASHU (*) [WEISHU + 1]); static void jianli_sjb (SHUJUBIAO **); // create a data table static SF wenhe (SHUZI_GESHU * const, const DASHU * const); static SF wenhe (SHUZI_GESHU * const p_sz_gs, const DASHU * const p_he) {int sz_gs_he [JINZHI] = {0}; // if (chaoguo_W (p_he) = SHI // exceeding W bits | less than W bits | buzu_W (p_he) = SHI) {return FOU;} qiu_sz_gs (& Sz_gs_he, p_he); // number of each number in the sum if (memcmp (sz_gs_he, * p_sz_gs, sizeof sz_gs_he) = 0) {return SHI;} return FOU ;} // create a data table static void jianli_sjb (SHUJUBIAO ** p_p_sjb) {if (* p_p_sjb = malloc (sizeof (SHUJUBIAO) = NULL) {// # include <stdlib. h> exit (! EXIT_SUCCESS) ;}{ int I, j; for (I = 0; I <JINZHI-1; I ++) {ds_fuzhi (* (** p_p_sjb + I) + 0, 0); // The first column is 0 ds_fuzhi (* (** p_sjb + I) + 1, 1); // The second column is assigned 1 for (j = 0; j <N; j ++) {// evaluate N power ds_chengyi (* (** p_p_sjb + I) + 1, JINZHI-1-I );} for (j = 2; j <= WEISHU; j ++) {(* (** p_p_sjb + I) [j] = (* (** p_p_sjb + I )) [J-1]; ds_jiaru (* p_p_sjb + I) + j, * (* p_p_sjb + I) + 1); }}} extern void qiongju (void) {SHUJUBIAO * p_sjb = NULL; jianli_sjb (& p_sjb); // create a data table xunhuan (WEISHU, JINZHI-1, * p_sjb); free (p_sjb);} sta