hdu1248--寒冰王座 这么久了的第一个背包问题 ^_^

View Code
 1 //Accepted    1248    93MS    2332K    512 B    Java
 2 import java.util.Scanner;
 3 
 4 public class Main {
 5     
 6     public static void main(String[] args) {
 7     
 8         Scanner sc = new Scanner(System.in);
 9         int b[] = {150,200,350};
10         int ans[] =  new int [10001];
11         for(int k = 1;k <= 10000 ;++k){
12             for(int j = 0 ; j < 3 ; ++ j){
13                 
14                 if(k - b [j] >= 0 ){
15                     ans[k] = Math.max(ans[k], ans[k-b[j]] + b[j]);
16                 }        
17             }
18         }
19         int t = sc.nextInt();
20         for(int i = 1; i <= t ; ++i ){
21             
22             int n = sc.nextInt();
23             System.out.println(n -  ans[n]);
24         }
25     }
26 }
posted @ 2012-09-07 17:29  Wheat″  阅读(182)  评论(0)    收藏  举报