Money System

来源:互联网 发布:电信网络经常闪断 编辑:程序博客网 时间:2024/05/16 00:38
 
/*ID: daniel.20LANG: JAVATASK: money */import java.io.*;import java.util.*;public class money {    static int target, num;    static int[] arr;    static long[] table;    public static void initial() throws Exception {        BufferedReader reader = new BufferedReader(new FileReader("money.in"));        StringTokenizer st = new StringTokenizer(reader.readLine());        num = Integer.parseInt(st.nextToken());        target = Integer.parseInt(st.nextToken());        arr = new int[num];        int count = 0;        while (count < num) {            if (st.hasMoreTokens()) {                arr[count++] = Integer.parseInt(st.nextToken());            } else {                st = new StringTokenizer(reader.readLine());            }        }        table = new long[10001];        table[0] = 1;    }    public static void dp() throws Exception {        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("money.out")));        for (int i = 0; i < num; ++i) {            for (int j = arr[i]; j <= target; ++j) {                table[j] += table[j - arr[i]];            }        }        out.println(table[target]);        out.close();    }    public static void main(String[] args) throws Exception {        initial();        dp();        System.exit(0);    }}


完全背包,写的比较顺利,30分钟就搞定了,输入数据没看清有多行,wa一次

感觉代码算比较简洁了.  继续!

原创粉丝点击