Codevs 2,055 Collection Division

Source: Internet
Author: User

"Title description"

For a set of contiguous integers from 1 to N (1<=n<=39), divided into two sub-sets, the sum of the numbers of each set is equal.

For example, if n=3, for {A-D} can be divided into two sub-sets, all of their numbers are equal: {3} and {a}

This is the only kind of division (the Interchange collection location is considered the same partitioning scheme and therefore does not increase the total number of partitioning schemes).

If the n=7, there are four ways to divide the set {1,2,3,4,5,6,7}, each subset of the subsets of each of the numbers and is equal:

{1,6,7} and {2,3,4,5}; {2,5,7} and {1,3,4,6};

{3,4,7} and {1,2,5,6}; {1,2,4,7} and {3,5,6}

Input

A positive integer n,1<=n<=39

Output

A number that divides the number of methods in the collection.

"Sample Input"

7

"Sample Output"

4

"Problem-solving ideas"

This is a backpack-type DP, for the kind of scheme, F[I,J] represents the number of the first I number of the scheme of J

Positive push: f[i,j]:=f[i-1,j]+f[i-1,j-i];

Initial conditions: f[1,1]:=1; F[1,0]:=1;

Backward (F[i,j] means the value of I~n is J)

F[i,j]:=f[i+1,j]+f[i+1,j-i];

Initial conditions: f[n,n]:=1; F[n,0]:=1;

1  ProgramT2;2 varN,sum,i,j:longint;3F:Array[1.. the,0.. -] ofLongint;4 begin5 read (n);6Sum:= (n+1) *nDiv 2;7     ifSumMoD 2=1  Then//Special Award8     begin9Write0);Ten Halt; One     End; ASum:=sumDiv 2; -f[1,1]:=1;//The method for taking the number 1 from the first 1 numbers is 1, the same as -f[1,0]:=1; the  -      fori:=2  toN-1  Do//default n in another array -          forj:=0  to(i+1) *iDiv 2  Do -         begin +f[i,j]:=f[i-1, j]; -             ifj-i>=0  Thenf[i,j]:=f[i,j]+f[i-1, j-i];//Anti-border +         End; AWriteln (f[n-1, sum]); at End.

Codevs 2,055 Collection Division

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.