题目地址:点击打开链接
就是搜索订单就可以了
#include <iostream> #include <cstring> using namespace std; struct Station { int start; int end; int num_of_people; }; const int maxsize = 25; Station Orders[maxsize]; int people_num_of_station[10]; int max_people,num_of_station,num_of_orders; int ans; bool check() { for(int i=0;i<=num_of_station;++i) if(people_num_of_station[i]>max_people) return false; return true; } void dfs(int val,int sum) { if(sum>ans) ans=sum; for(int i=val;i<num_of_orders;++i) { for(int j=Orders[i].start;j<Orders[i].end;++j) people_num_of_station[j]+=Orders[i].num_of_people; if(check()) dfs(i+1,sum+Orders[i].num_of_people*(Orders[i].end-Orders[i].start)); for(int j=Orders[i].start;j<Orders[i].end;++j) people_num_of_station[j]-=Orders[i].num_of_people; } } int main() { while(cin>>max_people>>num_of_station>>num_of_orders) { if(max_people==0&&num_of_station==0&&num_of_orders==0) break; for(int i=0;i<num_of_orders;++i) cin>>Orders[i].start>>Orders[i].end>>Orders[i].num_of_people; ans=-1; memset(people_num_of_station,0,sizeof(people_num_of_station)); dfs(0,0); cout<<ans<<endl; } return 0; }
UVa301 - Transportation,布布扣,bubuko.com
原文:http://blog.csdn.net/leizh007/article/details/23202941