• <input id="auww4"></input>
  • <input id="auww4"><acronym id="auww4"></acronym></input>
  • <input id="auww4"><u id="auww4"></u></input>
    <object id="auww4"><acronym id="auww4"></acronym></object>
    <menu id="auww4"></menu><input id="auww4"><u id="auww4"></u></input>
    <input id="auww4"><u id="auww4"></u></input>
  • F.A.Q
    Hand In Hand
    Online Acmers
    Forum | Discuss
    Statistical Charts
    Problem Archive
    Realtime Judge Status
    Authors Ranklist
     
         C/C++/Java Exams     
    ACM Steps
    Go to Job
    Contest LiveCast
    ICPC@China
    Best Coder beta
    VIP | STD Contests
    Virtual Contests
        DIY | Web-DIY beta
    Recent Contests
    Author ID 
    Password 
     Register new ID

    JAVA版AC,分享一下

    Posted by Kevin234 at 2018-08-10 09:03:38 on Problem 1114
    (5)  


    import java.util.Arrays;
    import java.util.Scanner;
    public class Main{
    	public static void main(String[] args) {
    		Scanner in =new Scanner(System.in);
    		int T=in.nextInt();
    		while(T-->0) {
    			int E=in.nextInt(),F=in.nextInt();
    			int n=in.nextInt();
    			int p[]=new int[n];
    			int w[]=new int[n];
    			for(int i=0;i<n;i++) {
    				p[i]=in.nextInt();
    				w[i]=in.nextInt();
    			}
    			int totalweight=F-E;
    			int []dp=new int [totalweight+1];
    			Arrays.fill(dp, 1000000001);
    			dp[0]=0;
    			for(int i=0;i<n;i++) {
    				for(int j=w[i];j<=totalweight;j++) {
    					dp[j]=Math.min(dp[j], dp[j-w[i]]+p[i]);
    				}
    			}
    			if(dp[totalweight]==1000000001)
    				System.out.println("This is impossible.");
    			else
    				System.out.println("The minimum amount of money in the piggy-bank is "+dp[totalweight]+".");
    		}	
    	}
    }

    Followed by:


    Post your reply here:

    Author ID
    Password
    Title
    Content  
     
    Hangzhou Dianzi University Online Judge 3.0
    Copyright © 2005-2020 HDU ACM Team. All Rights Reserved.
    Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
    Total 0.015600(s) query 5, Server time : 2020-10-14 09:05:14, Gzip enabled
    棋牌