UVA - 301 Transportation
2014-10-22 23:56
465 查看
Transportation |
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.
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 4 0 2 1 1 3 5 1 2 7 2 3 10 10 5 4 3 5 10 2 4 9 0 2 5 2 5 8 0 0 0
Sample
Output
1934
题意:
求取列车公司最大利润,对于某一区间的车票要拒则全拒,利用回溯来做;
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
using namespace std;
int stanum, staac, maxn, num;
struct edge
{
int u, v;
int val;
} e[33];
int a[10];
void dfs(int cur ,int pos)
{
int temp[10];
if(pos == num )
{
maxn = max(maxn , cur);
return ;
}
memcpy(temp, a, sizeof(a));
int i;
for(i = e[pos].u+1; i <= e[pos].v; i++)
{
if(a[i] + e[pos].val > staac)
break;
a[i] += e[pos].val;
}
if( i == e[pos].v + 1 )
dfs( cur + e[pos].val * (e[pos].v - e[pos].u), pos + 1);
memcpy(a, temp, sizeof(temp));
dfs(cur, pos + 1);
return ;
}
int main()
{
while(scanf("%d %d %d",&staac, &stanum, &num) != EOF && ( staac + stanum + num))
{
maxn = 0;
memset(a, 0, sizeof(a));
for( int i = 0; i < num; i++)
{
scanf("%d %d",&e[i].u, &e[i].v);
scanf("%d",&e[i].val);
}
dfs(0,0);
cout<<maxn<<endl;
}
}
相关文章推荐
- Uva 301 - Transportation
- uva 301 - Transportation 一切都是那么暴力
- uva301 - Transportation
- [回溯]Transportation UVA301
- uva 301 Transportation
- UVA - 301 Transportation
- UVA 301 Transportation
- UVa 301 & HDU 1456 & POJ 1040 - Transportation
- uva 301 Transportation
- uva301 - 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