zoukankan      html  css  js  c++  java
  • uva301

    题意就是给出一些station 然后一辆公车有人数限制。 问你求出最大的收益

    先对起点排个序。。然后就不用vis数组直接一个个递归下去。。一开始一直WA因为在main里没有枚举每个点。。。蛋疼

    题目:

      

    Transportation 

    Ruratania is just entering capitalism and is establishing new enterprising activities in many fields including 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.

    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

    19
    34

    代码:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <memory.h>
     4 #include <algorithm>
     5 using namespace std;
     6 
     7 int n,city,order;
     8 
     9 struct pas
    10 {
    11     int start,dest;
    12     int num;
    13     bool operator < (const pas& x) const
    14     {
    15         return start<x.start;
    16     }
    17 }G[100];
    18 int pG;
    19 int mark[100];
    20 int earns;
    21 void dfs(int u,int money)
    22 {
    23     pas& now = G[u];
    24     for(int i=now.start;i<now.dest;i++)
    25     {
    26         mark[i]+=now.num;
    27         if(mark[i]>n)
    28         {
    29             for(;i>=now.start;i--)
    30             {
    31                 mark[i]-=now.num;
    32             }
    33             return ;
    34         }
    35     }
    36     money += now.num*(now.dest-now.start);
    37 
    38     if(money>earns)earns=money;
    39 
    40     for(int i=u+1;i<pG;i++)
    41     {
    42         dfs(i,money);
    43     }
    44 
    45 
    46      for(int i=now.start;i<now.dest;i++)
    47      {
    48          mark[i]-=now.num;
    49      }
    50     return ;
    51 }
    52 
    53 
    54 int main()
    55 {
    56 
    57     while(cin>>n>>city>>order &&( n|| city||order))
    58     {
    59 
    60         for(int i=0;i<order;i++)
    61         {
    62             int s,e,p;
    63             cin>>s>>e>>p;
    64             G[pG++]=pas({s,e,p});
    65         }
    66 
    67         sort(G,G+pG);
    68         for(int i=0;i<order;i++)
    69         {
    70             dfs(i,0);
    71         }
    72         cout<<earns<<endl;
    73         pG=0;
    74         earns=0;
    75         memset(G,0,sizeof(G));
    76         memset(mark,0,sizeof(mark));
    77     }
    78 
    79     return 0;
    80 }
  • 相关阅读:
    ACDream
    HDU
    拼音码和五笔码生成规则
    XML与DataTable相互转换
    如何给gridControl动态的添加合计
    SqlBulkCopy将DataTable中的数据批量插入数据库中
    截取中间字符
    将Excel表格数据转换成Datatable
    DevExpress GridControl 使用方法技巧 总结 收录整理
    C#小技巧
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3479483.html
Copyright © 2011-2022 走看看