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