Hdu 5119 (similar to the state definition of the partition number) (counting problem in DP)

Source: Internet
Author: User

Title Description: How many of the number of scenarios in the N number are different or greater than m ?

Set stateF[i][j]Pre-RepresentativeIthe number is different or the value isJthe number of programmes hasF[i][j]species, then forJTo either choose the firstIthe number and the previousi-1some number in the numberJ,F[i-1][j^a[i]],or do not choose the firstInumber, directly from the previousi-1Number CompositionJ,f[i-1][j]; F[i][j]=f[i-1][j^a[i]] + f[i-1][j]; Notice that theJThe value range is10^6about equal to2^ (), soNthe maximum number of values is also -a1.

Or the characteristic: any number and 0 phase is also or unchanged, any number with itself or 0

Set initial value f[0][0]=1;

Before using a backpack that scroll array to write, but will find d[i][j]= D[i-1][j] + d[i-1][j-v[i]; The j-v[i]<=j in the Knapsack equation. So j traverse from large to small, the value of this line is only related to the value of the previous row,

However, this problem j^a[i] may be greater than J, so the value of this line is not guaranteed to be related only to the value of the previous row.

#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<cstring>#include<algorithm>#defineSIZE 50#defineLL Long Longusing namespacestd; LL a[ -]; LL ans[ -][1148576];voidinit () {memset (ans,0,sizeof(ANS));}intMain () {//freopen ("Test.txt", "R", stdin);    intT; scanf ("%d",&t); intCAS =1;  while(T--) {LL n,m; scanf ("%i64d%i64d",&n,&m);        Init ();  for(inti =1; I <= N; i + +) {scanf ("%i64d",&A[i]); //Ans[a[i]] = 1;} LL All=pow (2, N); ans[0][0]=1;  for(inti =1; I <= N; i + +)        {             for(intj =0;j<1048576; j + +) Ans[i][j]= ans[i-1][j^a[i]]+ans[i-1][j]; } LL Answer=0;  for(intj=0; j<m;j++) Answer+=Ans[n][j]; printf ("Case #%d:%i64d\n", CAS ++,all-answer); }    return 0;}

Hdu 5119 (similar to the state definition of the partition number) (counting problem in DP)

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.