UVA - 301 Transportation
来源:互联网 发布:航迹规划 算法 编辑:程序博客网 时间:2024/06/05 15:04
题目大意:一辆列车限载 n 个人,共有 s 站,t 个订单,往下 t 行表示 t 个订单,每行三个数字分别是起始站,终点站,人数。对于每个订单可以选择载或不载(不能只载一部分人),然后每人每站一块,问最大利润。
解题思路:用一个 peo 数组来储存每站的人数,当大于限定人数时该订单不可取。
#include<iostream> #include<cstdio>#include<cmath>#include<string>#include<stdlib.h>#include<algorithm>using namespace std;struct order { int start, end, num;};order p[25];int ans, tmp, n, s, t;int peo[10];void dfs(int now) { if (now == t) { tmp = 0; for (int i = 0; i < s; i++) tmp += peo[i]; if (tmp > ans) ans = tmp; return; } int tag = 1; for (int i = p[now].start; i < p[now].end; i++) { if (peo[i] + p[now].num > n) { tag = 0; break; } } if (tag) { for (int i = p[now].start; i < p[now].end; i++) peo[i] += p[now].num; dfs(now+1); for (int i = p[now].start; i < p[now].end; i++) peo[i] -= p[now].num; } dfs(now+1);}int main() { while (scanf("%d%d%d", &n, &s, &t) != EOF && n+s+t) { for (int i = 0; i < t; i++) scanf("%d%d%d", &p[i].start, &p[i].end, &p[i].num); ans = 0; dfs(0); printf("%d\n", ans); }return 0; }
0 0
- UVa 301 - Transportation
- uva 301 - Transportation
- uva 301 - Transportation
- UVa 301 - Transportation
- Uva 301 Transportation
- UVa 301 - Transportation 回溯
- uva 301 Transportation
- UVa 301 - Transportation
- UVA 301 Transportation
- UVA 301 - Transportation
- uva 301 Transportation (DFS)
- uva 301 Transportation
- uva 301 Transportation
- UVa:301 Transportation
- UVa 301 - Transportation
- uva 301 - Transportation
- UVa 301 Transportation
- ( 回溯 )uva 301 - Transportation
- ASP.NET 首页性能的十大做法
- 利用pyinstaller将python3程序打包为exe文件
- java中的类方法和实例方法
- CF 15C
- 用python写个死锁
- UVA - 301 Transportation
- 美团推荐算法实战
- UVA - 10344 23 out of 5
- java基础总结
- UVA - 331 Mapping the Swaps
- iOS-GCD中dispatch source使用
- 剑指Offer_06 根据前序遍历和中序遍历序列 重建二叉树
- UIImage和UIImageView的区别
- https和http区别