习题16.1-4,区间图着色问题
#include <iostream>
using namespace std;
const int N=11;
int sec[N+1]={0};
int i=0;
typedef struct
{
int start;
int end;
}activity;
int recursive_act_select(activity act[], int k, int n)
{
int m=k+1;
while(m<=n&&act[m].start<act[k].end)
m+=1;
if(m<=n)
{
cout<<act[m].start<<','<<act[m].end<<' ';
sec[++i]=m;
recursive_act_select(act,m,n);
return 0;
}
else
return 0;
}
int main()
{
activity act[N+1]={{0,0},{1,4},{3,5},{0,6},{5,7},{3,9},{5,9},{6,10},{8,11},{8,12},{2,14},{12,16}};
// int s[N+1]={0,1,3,0,5,3,5,6,8,8,2,12};
//int f[N+1]={0,4,5,6,7,9,9,10,11,12,14,16};
cout << "Hello world!" << endl;
recursive_act_select(act,0,N);
cout<<'\n';
cout<<i;
//for (int j=0;j<N+1;j++)
// cout<<sec[j]<<' ';
return 0;
}