POJ-1040
来源:互联网 发布:js工厂方法 编辑:程序博客网 时间:2024/05/01 11:09
Transportation
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2986 Accepted: 1225
Description
Ruratania is just entering capitalism and is establishing new enterprising activities in many fields in- cluding transport. The transportation company TransRuratania is starting a new express train from city A to city B with several stops in the stations on the way. The stations are successively numbered, city A station has number 0, city B station number m. The company runs an experiment in order to improve passenger transportation capacity and thus to increase its earnings. The train has a maximum capacity n passengers. The price of the train ticket is equal to the number of stops (stations) between the starting station and the destination station (including the destination station). Before the train starts its route from the city A, ticket orders are collected from all onroute stations. The ticket order from the station S means all reservations of tickets from S to a fixed destination station. In case the company cannot accept all orders because of the passenger capacity limitations, its rejection policy is that it either completely accept or completely reject single orders from single stations.
Write a program which for the given list of orders from single stations on the way from A to B determines the biggest possible total earning of the TransRuratania company. The earning from one accepted order is the product of the number of passengers included in the order and the price of their train tickets. The total earning is the sum of the earnings from all accepted orders.
Write a program which for the given list of orders from single stations on the way from A to B determines the biggest possible total earning of the TransRuratania company. The earning from one accepted order is the product of the number of passengers included in the order and the price of their train tickets. The total earning is the sum of the earnings from all accepted orders.
Input
The input file is divided into blocks. The first line in each block contains three integers: passenger capacity n of the train, the number of the city B station and the number of ticket orders from all stations. The next lines contain the ticket orders. Each ticket order consists of three integers: starting station, destination station, number of passengers. In one block there can be maximum 22 orders. The number of the city B station will be at most 7. The block where all three numbers in the first line are equal to zero denotes the end of the input file.
Output
The output file consists of lines corresponding to the blocks of the input file except the terminating block. Each such line contains the biggest possible total earning.
Sample Input
10 3 40 2 11 3 51 2 72 3 1010 5 43 5 102 4 90 2 52 5 80 0 0
Sample Output
1934
#include <stdio.h>#include <string.h>int orders[27][4];int maxPeoples, endStation, numOrders;;int max;int leane[8];void train(int n, int sum){ int i; if (sum > max) max = sum; if(n >= numOrders) return; for (i = orders[n][0]; i < orders[n][1]; i++) if (leane[i]+orders[n][2] > maxPeoples) break; if (i >= orders[n][1]) { for (i = orders[n][0]; i < orders[n][1]; i++) leane[i] += orders[n][2]; train(n+1, sum+orders[n][3]); for (i = orders[n][0]; i < orders[n][1]; i++) leane[i] -= orders[n][2]; } train(n+1, sum);}int main(){ int i; int a, b, p; while (scanf("%d%d%d", &maxPeoples, &endStation, &numOrders), maxPeoples||endStation||numOrders) { memset(leane, 0, sizeof(leane)); for (i = 0; i < numOrders; i++) { scanf("%d%d%d", &a, &b, &p); orders[i][0] = a; orders[i][1] = b; orders[i][2] = p; orders[i][3] = (b-a)*p; } max = 0; train(0, 0); printf("%d\n", max); } return 0;}
- poj 1040
- POJ-1040
- POJ 1040 典型回溯!
- poj 1040 Transportation
- poj 1040 Transportation
- POJ-1040-Transportation
- Transportation-POJ 1040
- POJ 1040 Transportation DFS
- POJ 1040 Transportation
- poj-1040-Transportation
- POJ 1040 Transportation 笔记
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- CentOS 6 rescue模式 初体验
- java 第3天笔记
- 增加datanode新节点
- 学习Android界面设计的超级利器HierarchyView.bat
- How to: Set the ProtectionLevel Property
- POJ-1040
- Windows Storage Server 2008 R2 下载安装
- Linux下分区详解之--Fdisk
- android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
- G-Sockets(IOCP) 2.5 Demo 源码 (VC2008 & Delphi7/2010)下载
- php的set_include_path与get_include_path()的用法
- 线性表基础知识(一)
- 改变WP7程序启动的页面Page.xaml
- Myeclipse 6.0.1下载,支持eclipse3.3.1