Try to use backtracking to solve reasoning problems

Publisher:Harmonious222Latest update time:2015-05-15 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include stdio.h
class TuiLi //Inference class

//Private method part
protected: 

SYSTEMTIME TIME; //Standard system time storage structure with 8 members and 16 bytes

struct FZ
{
int ys;
int yp;
int gj;
int cw;
int yl;
};//House attribute structure

FZ Fz[5];//Define 5 houses
int Biao[120][5];//Define combination table
int gj,ys,yl,cw,yp;//Combination flag
int sz[25];

//Solve Sudoku with
int sudu[81]; //Record backtracking path with
bool sudu_ji[81]; //Used to mark the value indicated by the question
int SD[9][9]; //Sudoku chessboard

//Solve N queens problem
int N;//Used to input the scale of the queen problem. In this example, only 33 queens can be solved because of memory allocation. Changing the memory allocation size can increase the scale of the problem.
int hh[1024]; //Record the backtracking path for solving the 33 queens problem at most
int HH[33][33];//Queen problem chessboard



//Public method part 
public:
TuiLi(void); 
~TuiLi(void);
void init_biao(void);//Initialize the combination table
void print(void);//Screen output
void gx(void);//Refresh the reasoning result
int OK(void);//Inference pruning condition
int go(void);//Main entry method for reasoning questions

int ok_sd(void);//Sudoku pruning condition
int go_sd(void);//Solve the population point of Sudoku
void sd_in(void);//Board data input
void SD_in(void);//Get the question information
void sd_out(void);//Board data output
void sd_print(void);//Screen output result

int ok_hh(int m);//Queen problem pruning function
int ok_hh_sc(void);//Final test
int go_hh(void); //Queen problem entry point
void hh_init(void);//Initialize chessboard data
void hh_out(void);//Chessboard data refresh
void hh_print(void);//Output result

};
Reference address:Try to use backtracking to solve reasoning problems

Previous article:Backtracking algorithm 1
Next article:Chapter 15 XOR and NOT (X86 Assembly Tutorial)

Recommended Content
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号