区间图着色问题

习题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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值