标签:乘号 system.in 数据规模 ext 整数 next 钥匙 价格 max
1 import java.math.BigInteger; 2 import java.util.Arrays; 3 import java.util.Scanner; 4 5 6 public class Main { 7 static int n; 8 static int m; 9 static int[] a; 10 static int[] a1; 11 static int[][] b; 12 public static void main(String[] args) { 13 Scanner input = new Scanner(System.in); 14 n = input.nextInt(); 15 m = input.nextInt(); 16 a = new int[m+1]; 17 a1 = new int[m+1]; 18 b = new int[m+1][n+1]; 19 for(int i=1;i<=m;i++){ 20 a[i] = input.nextInt(); 21 a1[i] = input.nextInt(); 22 } 23 for(int i=1;i<=m;i++){ 24 for(int j=1;j<=n;j++){ 25 if(a[i]>j){ 26 b[i][j] = b[i-1][j]; 27 }else{ 28 b[i][j] = Math.max(b[i-1][j], b[i-1][j-a[i]]+a[i]*a1[i]); 29 } 30 } 31 } 32 System.out.println(b[m][n]); 33 34 } 35 36 }
标签:乘号 system.in 数据规模 ext 整数 next 钥匙 价格 max
原文地址:http://www.cnblogs.com/lolybj/p/6666945.html