Codevs1669 Transportation Equipment

Source: Internet
Author: User

  • Title Description Description
    After Germany relaxed its offensive against Britain, it pointed its finger at the northeast-the Soviet Union. In early 1943, the East line of the station head to the white-hot stage. According to reliable intelligence, more than 900,000 German troops in Kursk are ready to launch a great offensive. Therefore, Marshal Zhukov requires you to immediately transport large quantities of equipment from the Far East military plant to support the Kursk front. The train driver tells you that a train can hold up to a V-volume of weaponry, but you may not be able to fill it up because the train can carry a maximum of G units of weight. At the same time, the Military factory warehouse provides you with a list of equipment detailing the volume, weight and firepower of each piece of equipment. In order to effectively support Marshal Zhukov, you need to find a solution that maximizes the total firepower value.

  • Enter a description input Description
    The first line: V and G represent the maximum weight and volume. The second line: n means that the warehouse has n pieces of equipment; third to N+2 line: 3 number per line Ti Vi GI indicates the firepower value, volume and weight of the equipment;

  • outputs description output Description
    Outputs a number that represents the maximum firepower value that may be obtained

  • sample input to sample
    6 5
    4
    10 2 2
    20 3 2
    40 4 3
    30 3 3

  • sample output Sample outputs
    50

  • Data Range
    For 50% of data, v,g,n≤100
    For 100% of data, v,g,n≤1000

  • Solving
    Two-dimensional cost knapsack problem, the subject to meet the 01 backpack model, just the state to open another dimension, while storage volume and weight can be. The state transition equation and enumeration order are almost identical to the normal 01 backpack.

  • Revelation
    When the new topic is found to be distorted by the familiar dynamic programming problem, it is a more common method to add one dimension to meet the new limitation in the original state.

  • Code

#include <cstdio>#include <algorithm>using namespace STD;Const intMAXN =1010;intV, G, N, V[MAXN], G[MAXN], W[MAXN];intF[MAXN][MAXN];voidInit () {scanf("%d%d%d", &v, &g, &n); for(inti =1; I <= N; ++i) {scanf("%d%d%d", &w[i], &v[i], &g[i]); }}voidWork () { for(inti =1; I <= N; ++i) { for(intj = V; J >= V[i]; --J) { for(intK = G; K >= G[i];            --K) {F[j][k] = max (F[j][k], F[j-v[i]][k-g[i]] + w[i]); }        }    }printf("%d\n", F[v][g]);}intMain () {init (); Work ();return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codevs1669 Transportation Equipment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.