UVA 672 (DP)

Source: Internet
Author: User

Test instructions: There are n gangsters to enter a restaurant, the restaurant has a door, the initial size of the door is 0, the door will increase by 1 per second or decrease by 1 or unchanged, but the range in [0,k], and then each gangster has to arrive at the time of the restaurant ti, each person has a wealth value pi and their body value si, Only when the gangster arrives at the restaurant is the size of the door and Si equal before he can enter the restaurant, the restaurant will increase Pi, ask the restaurant to increase the total pi value is how much.
The F[i] indicates that the former I can allow the restaurant to increase the total pi value is how much, first the gangsters to the restaurant's time sequencing, and then compare between gangsters to reach the difference and the difference in size to determine if the former into the latter can also enter, f[i] = max (F[i], f[j] + pi).

#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>using namespace STD;Const intN = the;structGan {intT, p, s;} Gan[n];intN, K, T, F[n];BOOLCMP (gan A, gan b) {returnA.T < b.t;}intMain () {intCAsscanf("%d", &cas); while(cas--) {scanf("%d%d%d", &n, &k, &t); for(inti =1; I <= N; i++)scanf("%d", &gan[i].t); for(inti =1; I <= N; i++)scanf("%d", &AMP;GAN[I].P); for(inti =1; I <= N; i++)scanf("%d", &AMP;GAN[I].S); Sort (gan +1, gan +1+ N, CMP);memset(F,-1,sizeof(f)); f[0] =0; for(inti =1; I <= N; i++) { for(intj =0; J < I; J + +) {if(F[j]! =-1) {//If J can't go in, he can't judge if I can enter .                    inttemp = gan[i].t-gan[j].t;intTemp2 =fabs(GAN[I].S-GAN[J].S);if(temp >= temp2) f[i] = max (F[i], f[j] + GAN[I].P); }            }        }intres =0; for(inti =1; I <= N; i++) res = max (res, f[i]);printf("%d\n", res);if(CAS)printf("\ n"); }return 0;}

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

UVA 672 (DP)

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.