subset(2)

来源:互联网 发布:股票自动挂单软件 编辑:程序博客网 时间:2024/05/18 17:24
  
/*ID: daniel.20LANG: JAVATASK: subset */import java.io.*;public class subset {    static int size;    static int target;    static long table[] = new long[800];    static void work() throws Exception {        BufferedReader f = new BufferedReader(new FileReader("subset.in"));        size = Integer.parseInt(f.readLine());        target = (1 + size) * size / 4;        table[0] = 1;        dp();    }    static void dp() throws IOException {        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("subset.out")));        if (size * (size + 1) / 2 % 2 == 1) {            out.println(0);            out.close();            return;        }        for (int i = 1; i <= size; ++i) {            for (int j = target; j >= i; --j) {                table[j] += table[j-i];            }        }        out.println(table[target] / 2);        out.close();    }    public static void main(String[] args) throws IOException, Exception {        work();        System.exit(0);    }}


之前就想好要写一个简化版本的背包,用滚动数组优化.

代码算比较简单了,实现完成. 继续A题

原创粉丝点击