poj 1040 Transportation
2011-07-22 16:56
176 查看
#include<iostream> //dfs #include<algorithm> using namespace std; struct node { int s,t,num; bool operator<(const node& o) { if(s==o.s) return t<o.t; return s<o.s; } }pas[30]; int cap,b,order,arr[10],res; void dfs(int i,int sum) { if(i==order) { res=max(res,sum); return; } int temp=sum; //剪枝 for(int j=i;j<order;++j) temp+=(pas[j].t-pas[j].s)*pas[j].num; if(temp<=res) return; for(int j=i;j<order;++j) { if(arr[pas[j].s]+pas[j].num>cap) { if(j==order-1) //这一步不可缺少 res=max(res,sum); continue; } for(int k=pas[j].s;k<pas[j].t;++k) //注意不是k<=pas[j].t arr[k]+=pas[j].num; dfs(j+1,sum+(pas[j].t-pas[j].s)*pas[j].num); for(int k=pas[j].s;k<pas[j].t;++k) arr[k]-=pas[j].num; } } int main() { //freopen("F:\\c++.txt", "r", stdin ) ; while(cin>>cap>>b>>order&&cap) { for(int i=0;i<order;++i) cin>>pas[i].s>>pas[i].t>>pas[i].num; sort(pas,pas+order); memset(arr,0,sizeof(arr)); res=0; dfs(0,0); cout<<res<<endl; } return 0; }
相关文章推荐
- POJ1040 Transportation
- poj1040 Transportation(DFS)
- Transportation-POJ 1040
- POJ1040 HDU1456 UVA301 UVALive5516 Transportation题解
- POJ 1040 Transportation
- POJ-1040-Transportation
- poj 1040 Transportation 深搜剪枝
- UVa 301 & HDU 1456 & POJ 1040 - Transportation
- POJ 1040 Transportation
- poj 1040 Transportation
- poj-1040-Transportation
- POJ-1040
- 2018_1_24_poj_1040_回溯
- POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
- Heavy Transportation POJ - 1797
- 最短路 - C - Heavy Transportation POJ - 1797
- poj-openjudge 1040:Bamboo Forest of the Lost 解题报告
- DFS深度搜索算法实现深度探究解析-以POJ 1040为例
- Heavy Transportation POJ - 1797
- <poj1040>Transportation