hdu--5119--number of decision scenarios DP

Source: Internet
Author: User

In fact, the Beijing station DP are not expected to be difficult.

But.. ..

Dp[x,y] Indicates the number of scenarios with the first X number of XOR values ==y

When transferring, you can first assign the upper level fully to this layer and assume that a[i] does not participate in XOR

Then A[i] is different from the upper value or needs to traverse all the scenarios 2 times

I was worried about Tle, but N was only 40.

I didn't use the scroll array to open the 40 directly at first.

Then an open scrolling array I don't know why I've been re ...

A long time to find that I will dp[x,y] the first open to 3 can be opened into 2 No, I'm depressed.

Obviously only can take 0 or 1 ah because the result of num&1 is not only 0 or 1?

No words ...

Not to understand. If I understand, I'll make up the reason below.

1#include <iostream>2#include <cstring>3 using namespacestd;4 5typedefLong LongLL;6 intN;7 Const intSize =1000000;8LL dp[2][size+Ten];9 inta[ $];Ten  One voidSolve () A { -      for(inti =1; I<=n; i++ ) -     { the          for(intj =0; J<=size; J + + ) -         { -dp[i&1][J] = dp[! ( i&1)][j]; -         } +          for(intj =0; J<=size; J + + ) -         { +dp[i&1] [J^a[i]] + = dp[! ( i&1)][j]; A         } at     } - } -  - intMain () - { -Cin.sync_with_stdio (false); in     intT, M; - LL ans; toCIN >>T; +      for(intK =1; k<=t; k++ ) -     { theCIN >> N >>m; *Memset (DP,0,sizeof(DP)); $          for(inti =1; I<=n; i++ )Panax Notoginseng         { -CIN >>A[i]; the         } +dp[0][0] =1; AAns =0; the solve (); +          for(inti = m; I<=size; i++ ) -         { $Ans + = dp[n&1][i]; $         } -cout <<"Case #"<< k <<": "<< ans <<Endl; -     } the     return 0; -}
View Code
1#include <iostream>2#include <cstring>3 using namespacestd;4 5typedefLong LongLL;6 intN;7 Const intSize =1000000;8LL dp[3][size+Ten];9 inta[ $];Ten  One voidSolve () A { -      for(inti =1; I<=n; i++ ) -     { the          for(intj =0; J<=size; J + + ) -         { -dp[i&1][J] = dp[! ( i&1)][j]; -         } +          for(intj =0; J<=size; J + + ) -         { +dp[i&1] [J^a[i]] + = dp[! ( i&1)][j]; A         } at     } - } -  - intMain () - { -Cin.sync_with_stdio (false); in     intT, M; - LL ans; toCIN >>T; +      for(intK =1; k<=t; k++ ) -     { theCIN >> N >>m; *Memset (DP,0,sizeof(DP)); $          for(inti =1; I<=n; i++ )Panax Notoginseng         { -CIN >>A[i]; the         } +dp[0][0] =1; AAns =0; the solve (); +          for(inti = m; I<=size; i++ ) -         { $Ans + = dp[n&1][i]; $         } -cout <<"Case #"<< k <<": "<< ans <<Endl; -     } the     return 0; -}
View Code

Today

Nightmare

It's raining.

Waiting for a man's coffee

Waiting for a phone call from a person

hdu--5119--number of decision scenarios 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.