10177_FenceRails

2022-5-16 18:16| 发布者: Hocassian| 查看: 70| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-3-89504631198000-Problem List-采集的数据-后羿采集器.html

Pro.ID

10177

Title

Fence Rails

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=10177

AC

3

Submit

8

Ratio

37.50%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Farmer John is trying to erect a fence around part of his field. He has decided on the shape of the fence and has even already installed the posts, but he's having a problem with the rails. The local lumber store has dropped off boards of varying lengths; Farmer John must create as many of the rails he needs from the supplied boards.

    Of course, Farmer John can cut the boards, so a 9 foot board can be cut into a 5 foot rail and a 4 foot rail (or three 3 foot rails, etc.). Farmer John has an 'ideal saw', so ignore the 'kerf' (distance lost during sawing); presume that perfect cuts can be made.

    The lengths required for the rails might or might not include duplicates (e.g., a three foot rail and also another three foot rail might both be required). There is no need to manufacture more rails (or more of any kind of rail) than called for the list of required rails.

    输入

    Multiple test cases. For each case :

    Line 1:    N (1 ≤ N ≤ 50), the number of boards

    Line 2..N+1:   N lines, each containing a single integer that represents the length of one supplied board

    Line N+2:    R (1 ≤ R ≤ 1023), the number of rails

    Line N+3..N+R+1:   R lines, each containing a single integer (1 ≤ ri ≤ 128) that represents the length of a single required fence rail

    输出

    Description

    Farmer John is trying to erect a fence around part of his field. He has decided on the shape of the fence and has even already installed the posts, but he's having a problem with the rails. The local lumber store has dropped off boards of varying lengths; Farmer John must create as many of the rails he needs from the supplied boards.

    Of course, Farmer John can cut the boards, so a 9 foot board can be cut into a 5 foot rail and a 4 foot rail (or three 3 foot rails, etc.). Farmer John has an 'ideal saw', so ignore the 'kerf' (distance lost during sawing); presume that perfect cuts can be made.

    The lengths required for the rails might or might not include duplicates (e.g., a three foot rail and also another three foot rail might both be required). There is no need to manufacture more rails (or more of any kind of rail) than called for the list of required rails.

    Input

    Multiple test cases. For each case :

    Line 1:    N (1 ≤ N ≤ 50), the number of boards

    Line 2..N+1:   N lines, each containing a single integer that represents the length of one supplied board

    Line N+2:    R (1 ≤ R ≤ 1023), the number of rails

    Line N+3..N+R+1:   R lines, each containing a single integer (1 ≤ ri ≤ 128) that represents the length of a single required fence rail

    Output

    For each case, output a single integer on a line that is the total number of fence rails that can be cut from the supplied boards. Of course, it might not be possible to cut all the possible rails from the given boards.

    Sample Input

    4
    30
    40
    50
    25
    10
    15
    16
    17
    18
    19
    20
    21
    25
    24
    30

    Sample Output

    7

    Hint

    This is a high dimensionality multiple knapsack problem, so we just have to test the cases. Given that the search space has a high out-degree, we will use depth first search with iterative deepening in order to limit the depth of the tree. However, straight DFSID will be too slow, so some tree-pruning is necessary.

    Source

    样例输入

    4
    30
    40
    50
    25
    10
    15
    16
    17
    18
    19
    20
    21
    25
    24
    30

    样例输出

    7

    提示

    This is a high dimensionality multiple knapsack problem, so we just have to test the cases. Given that the search space has a high out-degree, we will use depth first search with iterative deepening in order to limit the depth of the tree. However, straight DFSID will be too slow, so some tree-pruning is necessary.


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部