#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <climits>
#include <map>
#include <stack>
#include <list>
#include <set>
#include <ctime>
#include <cstdlib>
#include <sstream>
#define FILE_IN freopen ("Input.txt", "R", stdin)
#define MAX 100005
#define INF 0x3f3f3f3f
#define HASH 100019
#define MAX_C 100
#define MAP_IT (type1,type2) map<type1,type2>::iterator
using namespace Std;
#define LL Long Long
#define FF (X,y,i) for (int i=x;i<y;i++)
struct Process {
int num;
vector<int>max;
vector<int>occupied;
vector<int>need;
};
vector<int>ava;
vector<process>processlist;
BOOL Test (VECTOR<INT>PMU) {
Vector<process>temppro = processlist;
Vector<int>tempava = Ava;
for (int i = 0; i < pmu.size (); i++) {
int currentpro = Pmu[i];
for (int i = 0; i < temppro[currentpro].need.size (); i++) {
if (Temppro[currentpro].need[i] > Tempava[i])
return 0;
}
for (int i = 0; i < temppro[currentpro].occupied.size (); i++) {
Tempava[i] + = Temppro[currentpro].occupied[i];
}
}
return true;
}
int main () {
int numprocess, numres;
cout << "Please input number of processes" << Endl;
Cin >> Numprocess;
Processlist.resize (numprocess);
cout << "Please input the number of resource types" << Endl;
Cin >> Numres;
for (int i = 0; i < numprocess; i++)
{
Processlist[i].max.resize (Numres);
Processlist[i].occupied.resize (Numres);
Processlist[i].need.resize (Numres);
}
Ava.resize (Numres);
cout << kind of resource, please input it's number of remaining instances "<< Endl;
for (int i = 0; i < numres; i++)
CIN >> Ava[i];
cout << "For each process, input the occuied instance it owns by the order" << Endl;
for (int i = 0; i < numprocess; i++) {
cout << "Process" << I << ":" << Endl;
for (int j = 0; J < Numres; J + +) {
CIN >> Processlist[i].occupied[j];
}
}
cout << "For each process, input the Maxium instance it needs" << Endl;
for (int i = 0; i < numprocess; i++) {
cout << "Process" << I << ":" << Endl;
for (int j = 0; J < Numres; J + +) {
CIN >> Processlist[i].max[j];
PROCESSLIST[I].NEED[J] = processlist[i].max[j]-processlist[i].occupied[j];
}
}
vector<int>possiblepermu;
for (int i = 0; i < processlist.size (); i++) Possiblepermu.push_back (i);
while (Next_permutation (Possiblepermu.begin (), Possiblepermu.end ())) {
if (test (POSSIBLEPERMU)) {
for (int i = 0; i < possiblepermu.size (); i++)
cout << Possiblepermu[i] << "";
cout << Endl;
}
}
}
Banker algorithm-Safe sequence full list implementation