/ * Author: Central China Normal University SunJunyi * // * Compiler: Turboc2.0 * // * The basic idea of the algorithm: backtracking * / # include
INT ASS [N], NEED [N], R [M], PNUM, RNUM, TOP = -1; / * ASS is the allocation matrix of processes and resources, NEED is the demand matrix of processes and resources. * / Worknode current, stack [n]; / * Current For the current working node, Stack is the working node stack * /
Void add (int [】, int []); / * vector add * / void init (); / * Initialization * / void output (); / * Output result * / int small (int [】, int [] ); / * Vector comparison * / int BankAlgo (); / * Bank algorithm * /
INT main () {int CT = 0; CLRSCR (); init (); CT = BankAlgo (); if (ct) Printf ("/ NIT IS SAFE, AND IT HAS% D Solutions / N", CT); ELSE Printf ("/ nit is unsafe / n"); return 0;}
Void init () {INT I, J; Printf ("Process Number:"); Scanf ("% D", & PNUM); Printf ("Resource Number:"); Scanf ("% D", & RNUM); Printf "Resource Series:"); for (i = 0; i Void add (int x [】, int y []) {INT i; for (i = 0; i INT Small (int x [】, int y []) {INT i; for (i = 0; i