/* 实验以3.7.4为例
N=5个进程(p0,p1,p2,p3,p4) M=3类资源(A=10,B=5,C=7)
在T0时刻资源分配如下
Max Allocation Need Available
A B C A B C A B C A B C
p0 7 5 3 0 1 0 7 4 3 3 3 2
p1 3 2 2 2 0 0 1 2 2
p2 9 0 2 3 0 2 6 0 0
p3 2 2 2 2 1 1 0 1 1
p4 4 3 3 0 0 2 4 3 1
*/
#include <iostream>
using namespace std;
#define N 5//进程数
#define M 3//资源数
int Available[M]={3,3,2};//可用资源向量
//最大需求矩阵
int Max[N][M]={ {7,5,3},{3,2,2},{9,0,2},{2,2,2},{4,3,3} };
//分配矩阵
int Allocation[N][M]={ {0,1,0},{2,0,0},{3,0,2},{2,1,1},{0,0,2} };
//需求矩阵
int Need[N][M] = { {7,4,3},{1,2,2},{6,0,0},{0,1,1},{4,3,1} };
//请求向量
int Request[M];
bool savety(int allocation[N][M],int need[N][M],int ava[M]);
int check(int a,int request[]);
void execute(int a,int request[M]);
void print();
void result(int res);
int main()
{
//安全性检测
int allocation[N][M];
int need[N][M];
int ava[M];
for(int i=0;i<M;i++) ava[i]=Available[i];
for(int i=0;i<
06-01
04-21