//poj 1040
//sep9
#include <iostream>
using namespace std;
int n,m,order_num,ans;
struct Order{
int s,t,num,val;
}orders[32];
int passengers[16],most_earn[32];
void dfs(int cur,int sum_value)
{
if(cur>=order_num){
ans=max(ans,sum_value);
return ;
}
if(sum_value+most_earn[cur]<=ans) return ;
dfs(cur+1,sum_value);
bool success=true;
for(int i=orders[cur].s;i<orders[cur].t;++i)
if(passengers[i]+orders[cur].num>n){
success=false;
break;
}
if(success){
for(int i=orders[cur].s;i<orders[cur].t;++i) passengers[i]+=orders[cur].num;
dfs(cur+1,sum_value+orders[cur].val);
for(int i=orders[cur].s;i<orders[cur].t;++i) passengers[i]-=orders[cur].num;
}
}
int main()
{
while(scanf("%d%d%d",&n,&m,&order_num)==3){
if(n==0&&m==0&&order_num==0) break;
memset(most_earn,0,sizeof(most_earn));
for(int i=0;i<order_num;++i){
scanf("%d%d%d",&orders[i].s,&orders[i].t,&orders[i].num);
orders[i].val=(orders[i].t-orders[i].s)*orders[i].num;
}
for(int i=order_num-1;i>=0;--i) most_earn[i]=most_earn[i+1]+orders[i].val;
ans=0;
memset(passengers,0,sizeof(passengers));
dfs(0,0);
printf("%d\n",ans);
}
return 0;
}
poj 1040 Transportation 深搜剪枝
最新推荐文章于 2020-07-23 14:42:42 发布