标签:
活动选择问题的递归调用算法
#include<iostream> using namespace std; #define N 11 struct node{ int id; int satrt; int end; }A[N+1]; void recursive_activity_seclect(int k,int n) { int m=k+1; while(m<=n&&A[m].satrt<A[k].end) m=m+1; if(m<=n) { cout<<"一个元素是 "<<m<<endl; recursive_activity_seclect(m,n); } cout<<endl; return ; } int main() { int i; for(i=0;i<=N;++i) { A[i].id=i; if(i==0) { A[i].satrt=0; A[i].end=0; } else { cin>>A[i].satrt>>A[i].end; } } recursive_activity_seclect(0,N); system("pause"); return 0; }
标签:
原文地址:http://blog.csdn.net/qq_22335577/article/details/42235197