Luogu P1802-5 times experience days (java implementation)

Luogu P1802-5 times experience day

topic background

Le Dou is now active! Every time you hit a person, you can get 5 times experience! But absi2011 looked helplessly at those friends who were higher in level than him, wondering if he could kill them. Get rid of those who can get a lot of experience.

topic description

Now absi2011 has taken out x mini-packs of drugs (it’s shameful to hit people with drugs...), ready to start fighting with those people

Because the mini-pack can only be used once, so absi2011 should use these medicines carefully. The tragedy is that if the attribute medicines used to defeat the person have not reached the minimum, he will lose if he hits people>.<So he uses 2 medicines to beat others, Others said that it takes 3 medicines to fight, so it means that you lose and these two attribute medicines are wasted.

Now there are n friends, who have the experience of losing and winning, and need to take a few drugs to beat them. Find the maximum experience (note that it must be multiplied by 5 at the end)

input format

Two numbers in the first line, n and x

There are three numbers in each of the following n lines, which respectively represent the experience gained by losing (lose[i]), the experience gained by winning (win[i]), and the number of medicines to be used at least after playing (use[i] ).

output format

An integer, the maximum amount of experience gained

Input and output samples

input#1

6 8
21 52 1
21 70 5
21 48 2
14 38 3
14 36 1
14 36 2

Output #1

1060

Instructions/Tips

【Hint】

During the five times experience activity, absi2011 always takes stamina potion instead of this attribute potion >.<

【data range】

For 10% of the data, x=0 is guaranteed

For 30% of the data, ensure that n<=10, x<=20

For 60% of the data, ensure that n<=100, x<=100, 10<=lose[i], win[i]<=100, use[i]<=5

For 100% data, guarantee n<=1000, x<=1000, 0<lose[i]<=win[i]<=1000000, 0<=use[i]<=1000

train of thought

State division f(i, j):
set: means the experience set that can be obtained by choosing from 1 to i, and the number of medicine bottles used does not exceed j: means choosing from 1 to i, and the number of medicine bottles used does not exceed j available experiencethe collection:Indicates the experience that can be obtained by choosing from 1 to i , and the number of medicine bottles used does not exceed j

Attribute: Max (up to) Attribute: Max (up to)attributes:M a x ( maximum )

Core:
For the i-th friend, we have two choices of calling or not. For the i-th friend, we have two options of calling or notFor the i -th friend , we have two options : call or not. State
transition:
choose to call: f ( i , j ) = f ( i − 1 , j − uer [ i ] ) + win [ i ] Choose to play: f(i,j) = f(i-1,j-uer[i])+win[i]Choose to hit : f ( i ,j)=f(i1,ju and r [ i ] )+win[i]

Choose not to fight: f ( i , j ) = f ( i − 1 , j ) + los [ i ] Choose not to fight: f(i,j) = f(i-1,j)+los[i]Choose not to type : f ( i ,j)=f(i1,j)+los[i]

core code

		for(int i=1;i<=n;i++) {
    
    	
			for(int j=0;j<=x;j++) {
    
    
				f[i][j] = f[i-1][j] + l[i];
				if(j>=u[i]) {
    
    
					f[i][j] = Math.max(f[i-1][j]+l[i],f[i-1][j-u[i]]+w[i]);
				}
			}
		}

full code

package p1802;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
public class Main {
    
    
	static int N = 1010;
	static long f[][] = new long[N][N];
	static int w[] = new int[N],l[] = new int[N],u[] = new int[N];
	public static void main(String[] args) throws Exception{
    
    
		Read r = new Read();
		int n = r.nextInt(),x = r.nextInt();
		for(int i=1;i<=n;i++) {
    
    
			l[i] = r.nextInt();w[i] = r.nextInt();u[i] = r.nextInt();
		}
		for(int i=1;i<=n;i++) {
    
    	
			for(int j=0;j<=x;j++) {
    
    
				f[i][j] = f[i-1][j] + l[i];
				if(j>=u[i]) {
    
    
					f[i][j] = Math.max(f[i-1][j]+l[i],f[i-1][j-u[i]]+w[i]);
				}
			}
		}
		System.out.println(f[n][x]*5);
	}
}
class Read{
    
    
	StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
	public int nextInt() throws Exception{
    
    
		st.nextToken();
		return (int)st.nval;
	}
}

Guess you like

Origin blog.csdn.net/gudada010/article/details/117524226