codevs2894, 2837, 1669, 2503, 3231

Source: Internet
Author: User

6.25 Backpack Review of dynamic planning

2894 TXX Exam

time limit: 1 sspace limit: 32000 KBtitle level: Golden Gold SolvingTitle Description Description

Txx was a poor man, and the exam became his nightmare. So he often sleeps in the exam to pass the time. Today he has to face an exam again, in order to ensure adequate sleep, he decided to do only K-minute topic. This test has n questions, the first question of the score is Pi points, need to spend ti minutes to solve (will be completed also get no points).

Please figure out how many points he has at least (the total score is the sum of all the topic scores).

Enter a description Input Description

First Row K

Second row n

Line three to line n+2 two numbers per line: Ti and pi

Output description Output Description

Txx min. deduction

Sample input Sample Input

5

3

2 6

1 3

4 7

Sample output Sample Output

6

Data range and Tips Data Size & Hint

100% of the data in,k<=100000,ti<=10000,pi<=10000;

30% of the data in,n<=20;

100% of the data, n<=500

Backpack Category: 01 backpack

#include <cstdio>#include<iostream>using namespacestd;#defineN 101000intv[n],c[n],f[n],k,n,sum;intMain () {scanf ("%d%d",&k,&N);  for(intI=1; i<=n;i++) {scanf ("%d%d", v+i,c+i); Sum+=C[i]; }     for(intI=1; i<=n;i++){         for(intj=k;j>=v[i];j--) {F[j]=max (f[j],f[j-v[i]]+C[i]); }} printf ("%d\n", sum-F[k]); return 0;}
2837 Review before the exam

time limit: 1 sspace limit: 128000 KBtitle level: Golden Gold SolvingTitle 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.

Backpack Category: 01 backpack

#include <cstdio>#include<iostream>using namespacestd;#defineN 101000intV[n],c[n],f[n],k,n;intMain () {scanf ("%d%d",&n,&k);  for(intI=1; i<=n;i++) {scanf ("%d%d", v+i,c+i); }     for(intI=1; i<=n;i++){         for(intj=k;j>=v[i];j--) {F[j]=max (f[j],f[j-v[i]]+C[i]); }} printf ("%d\n", F[k]); return 0;}
1669 Transport Equipment

time limit: 1 sspace limit: 256000 KBtitle level: Diamonds Diamond SolvingTitle 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;

Output description Output Description

Outputs a number that represents the maximum firepower value that may be obtained

Sample input Sample Input

6 5

4

10 2 2

20 3 2

40 4 3

30 3 3

Sample output Sample Output

50

Data range and Tips Data Size & Hint

"Data Range"

For 50% of data, v,g,n≤100

For 100% of data, v,g,n≤1000

Backpack Category: 01 backpack

#include <cstdio>#include<iostream>using namespacestd;#defineN 1010intv[n],c[n],g[n],f[n][n],m,n,q;intMain () {scanf ("%d%d%d",&n,&m,&q);  for(intI=1; i<=q;i++) {scanf ("%d%d%d", c+i,v+i,g+i); }     for(intI=1; i<=q;i++){         for(intj=v[i];j<=n;j++){             for(intk=g[i];k<=m;k++) {F[j][k]=max (f[j][k],f[j-v[i]][k-g[i]]+C[i]); }}} printf ("%d\n", F[n][m]); return 0;}
2503 lovelorn 28 days-Mending gifts

time limit: 1 sspace limit: 32000 KBtitle level: Golden Gold SolvingTitle Description Description

The last time he gave the girl a gift of N, because it is cheap, so all are broken, the girl is very concerned about these gifts, so decided to mend their own, but life is short ah, the girl is limited, she has a total of M minutes to mend gifts. Because the degree of damage is not the same, so the time to mend P is not the same, each gift, there is a girl's love degree is W, followed by a number h for the number of such gifts. Girls want to make their favorite degree and the biggest, then please smart you help her calculate a count! (Note: The gift is very much, not all can be mended, the girl does not have to spend all the time)

Enter a description Input Description

Line 1th 2 integers m,n
Line 2nd to line n+1 three integers per line p,w,h

Output description Output Description

An integer s indicates the greatest degree of affection

Sample input Sample Input

8 2
2 100 4
4 100 2

Sample output Sample Output

400

Data range and Tips Data Size & Hint

m<=10000

n<=100

p,h,w<=6000

Backpack Category: Multiple backpacks Naive algorithm
#include <cstdio>#include<iostream>using namespacestd;#defineN 10100intv[n],c[n],s[n],f[n],n,m;intMain () {scanf ("%d%d",&m,&N);  for(intI=1; i<=n;i++) {scanf ("%d%d%d", v+i,c+i,s+i); }     for(intI=1; i<=n;i++){         for(intj=m;j>=0; j--){             for(intk=0; k<=s[i];k++){                if(j-k*v[i]<0) Break; F[J]=max (f[j],f[j-k*v[i]]+k*C[i]); }}} printf ("%d\n", F[m]); return 0;}

Binary optimization

#include <cstdio>#include<iostream>#include<algorithm>using namespacestd;#defineN 10010inte[ -],v[n],c[n],f[n],m,n,n1;intMain () { for(intI=0; i<= -; i++) e[i]=1<<i; scanf ("%d%d",&m,&N);  for(intI=1, x,y,s;i<=n;i++) {scanf ("%d%d%d",&x,&y,&s); intt=0;  while(s>=E[t]) {v[++n1]=x*E[t]; C[N1]=y*E[t]; S-=e[t++]; }        if(s) {v[++n1]=x*s; C[N1]=y*s; }    }     for(intI=1; i<=n1;i++){         for(intj=m;j>=v[i];j--) {F[j]=max (f[j],f[j-v[i]]+C[i]); }} printf ("%d\n", F[m]); return 0;}
3231 Snacks

time limit: 1 sspace limit: 16000 KBtitle level: Golden Gold SolvingTitle Description Description

This is a foodie's paradise, too many snacks. Numerous.

Suppose there are n kinds of snacks on the island, each volume VI, the delicacy of WI.

Set a food eater's appetite C, and ask him to eat the greatest delicacy.

Enter a description Input Description

Two positive integers n C

n a positive integer, Vi

n a positive integer, Wi

Output description Output Description

Maximum Delicious value

Sample input Sample Input

4 10

2 5 1 9

10 24 1 100

Sample output Sample Output

101

Data range and Tips Data Size & Hint

n<=100,c<=10000,vi,wi<=1000

Can DP, can DFS

Backpack Category: 01 backpack

#include <cstdio>#include<iostream>using namespacestd;#defineN 10100intv[n],c[n],f[n],n,m;intMain () {scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) scanf ("%d", v+i);  for(intI=1; i<=n;i++) scanf ("%d", c+i);  for(intI=1; i<=n;i++){         for(intj=m;j>=v[i];j--) {F[j]=max (f[j],f[j-v[i]]+C[i]); }} printf ("%d\n", F[m]); return 0;}

codevs2894, 2837, 1669, 2503, 3231

Related Keywords:

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.