/* ID: lucien23prog: subsetlang: C ++ */# include <iostream> # include <fstream> using namespace STD; int main () {ifstream infile ("subset. in "); ofstream OUTFILE (" subset. out "); If (! Infile |! OUTFILE) {cout <"file operation failure! "<Endl; Return-1 ;}int N; infile >>n; If (N % 4! = 0 & (n + 1) % 4! = 0) {OUTFILE <0 <Endl; return 0;}/** using bitwise operations, always times out * // * long maxnum = (long) 1 <n)-1; int COUNT = 0; For (long I = 1; I <maxnum; I ++) {int sum0, sum1; sum0 = sum1 = 0; For (Int J = 0; j <n; j ++) {long temp = 1 <j; If (temp & I) = temp) {sum1 + = J + 1;} else {sum0 + = J + 1;} If (sum0 = sum1) {count ++ ;}} OUTFILE <count/2 <Endl; * // ** Dynamic Planning * requires that the first n numbers be divided into two subsets with the same sum. * In fact, the sum of the First n numbers can be sum = N (n + 1) the number of subsets of/4 * This can use the dynamic planning idea, that is, whether the subset contains N can be divided into two situations * That is, the sum of the first n-1 number is sum-N and the sum is the sum of the number of subsets of sum * Set S [I, j] for the number of subsets where the sum of numbers is J selected from the former number of I, there is * s [I, j] = s [I-1, J] + s [I-1, j-I], J-I> = 0 * s [I, j] = s [I-1, J], j-I <0 */INT sum = N * (n + 1)/4; long ** S = new long * [n + 1]; for (INT I = 0; I <= N; I ++) {s [I] = new long [Sum + 1] ();} s [1] [0] = s [1] [1] = 1; for (INT I = 2; I <= N; I ++) {for (Int J = 0; j <= sum; j ++) {if (I> J) // cannot put I {s [I] [J] = s [I-1] [J];} else {// available is [I] [J] = s [I-1] [J] + s [I-1] [J-I] ;}} OUTFILE <s [N] [Sum]/2 <Endl; return 0 ;}