# P1478 Tata pick Apples (upgrade version)

Source: Internet
Author: User

Tag: Sort ace means scan std CLU Node Air nbsp

Title Description

Another autumn, the Tautau apple tree has a fruit of n. Tata again ran to pick apples, this time she has a a-centimeter chair. When his hand is out of reach, he will stand on the chair and try again.

This time with the NOIp2005 popularization group first problem is different: Tata before moving stool, strength only left S. Of course, every time you pick an apple, you have to use a certain amount of effort. Tata want to know how many apples can be picked up before s<0.

Now known n apples to reach the height of the ground XI, chair height A, Tata hand straighten the maximum length B, Tata's remaining strength S, Tata pick an apple need the strength Yi, beg Tata can pick how many apples.

Input/output format Input Format:

Line 1th: Two number of apples N, strength s.

Line 2nd: The height of the two-digit chair A, Tata the maximum length of the hand straight B.

Line 3rd ~ Line 3+n-1: Two apples per row, Apple height XI, pick the strength that the Apple needs Yi.

output Format:

There is only one integer that represents the maximum number of apples the Tata can pick.

Input/Output sample Input Sample # #:
`8 1520 130120 3150 2110 7180 150 8200 0140 3120 2`
Sample # # of output:
`4`
Description

All data: n<=5000 a<=50 b<=200 s<=1000

``      xi<=280  yi<=100``
Title Description

Another autumn, the Tautau apple tree has a fruit of n. Tata again ran to pick apples, this time she has a a-centimeter chair. When his hand is out of reach, he will stand on the chair and try again.

This time with the NOIp2005 popularization group first problem is different: Tata before moving stool, strength only left S. Of course, every time you pick an apple, you have to use a certain amount of effort. Tata want to know how many apples can be picked up before s<0.

Now known n apples to reach the height of the ground XI, chair height A, Tata hand straighten the maximum length B, Tata's remaining strength S, Tata pick an apple need the strength Yi, beg Tata can pick how many apples.

Input/output format Input Format:

Line 1th: Two number of apples N, strength s.

Line 2nd: The height of the two-digit chair A, Tata the maximum length of the hand straight B.

Line 3rd ~ Line 3+n-1: Two apples per row, Apple height XI, pick the strength that the Apple needs Yi.

output Format:

There is only one integer that represents the maximum number of apples the Tata can pick.

Input/Output sample Input Sample # #:
`8 1520 130120 3150 2110 7180 150 8200 0140 3120 2`
Sample # # of output:
`4`
Description

All data: n<=5000 a<=50 b<=200 s<=1000

`` xi<=280 yi<=100`The eldest brother above thought of using DP solution, but that equation I really did not understand ,,,In fact, this question can be seen as a DP knapsack problem.we have a physical strength sfor each can pick (height within the range) Apple we only pick or not pick two possibilitiesso we're going to turn this problem into 01 knapsack problems.state transition EquationDp[i][j]=max (dp[i-1][j],dp[i-1][j-a[i].v]+1);By the way, in order to ensure the efficiency of the DP, I have all the apples in advance order, if the current Apple can not reach, indicating that the future of the apples are not enough, the direct exit will bethus arises a problem, dp[n][maxt] is not necessarily the maximum valueThe maximum value needs to be compared at each DP.This is the only difference between this question and the 01 backpack.`
`1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7 intN,maxt;8 intChair,hand;9 structnodeTen { One     intHigh ; A     intv; -}a[10001]; - intCompConstNode & A,ConstNode &b) the { -     if(a.high!=B.high) -     returna.high<B.high; -     Else  +     returna.v<B.V; - } + intdp[5001][1001]; A intans=0; at intMain () - { -scanf"%d%d%d%d",&n,&maxt,&chair,&hand); -Hand=hand+chair; -      for(intI=1; i<=n;i++) -scanf"%d%d",&a[i].high,&a[i].v); inSort (A +1, a+n+1, comp); -      for(intI=1; i<=n;i++) to     { +         if(hand>=A[i].high) -         { the              for(intj=0; j<=maxt;j++) *             { \$                 if(a[i].v<=j)Panax NotoginsengDp[i][j]=max (dp[i-1][j],dp[i-1][j-a[i].v]+1); -                 Else thedp[i][j]=dp[i-1][j]; +ans=Max (ans,dp[i][j]); A             } the              +         } -         Else \$          Break; \$     } -printf"%d", ans); -     return 0; the}`

P1478 Tata pick Apples (upgrade version)

Related Keywords:
Related Article

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.