Codevs 2837 Review before the exam

Source: Internet
Author: User

time limit: 1 sspace limit: 128000 KBtitle level: Golden Gold SolvingView Run ResultsTitle Description Description

Aiden to take the exam immediately, but he did not review how, so he decided to cram. He lists n points of knowledge and analyzes the time t required to review each knowledge point and the possible score K. He now has a T-time to review, and he wants to pick the right knowledge points to get the highest desired score in the shortest possible time.

Enter a description Input Description

The first line, two numbers, is N, T.

The next n rows, two numbers per line, T, K, indicate the time and desired score for a knowledge point.

Output description Output Description

A row, a number, that represents the highest desired score that can be obtained.

Sample input Sample Input

3 5

3 5

3 2

2 2

Sample output Sample Output

7

Data range and Tips Data Size & Hint

For 10% of data, 0<n≤10,0<t≤100.

For 50% of data, 0<n≤1000,0<t≤10000.

For 100% of data, 0<n≤5000,0<t≤10000,0<t,k≤1000.

Code:

#include <iostream>#include<cstdio>using namespacestd;intw[5010],c[5010],f[10010],n,t,n,t;intMain () {scanf ("%d%d",&n,&T);  for(intI=1; i<=n;i++) scanf ("%d%d",&w[i],&C[i]);  for(intI=1; i<=n;i++)    {         for(intj=t;j>=w[i];j--) F[j]=max (f[j-w[i]]+C[i],f[j]); } printf ("%d", f[t]); return 0;}

Idea: Simple 01 Big water problem don't say a note the size of the F array

Codevs 2837 Review before the exam

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.