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)