HDU 5119 Happy Matt friends--(backpack DP)

Source: Internet
Author: User

  Test instructions: With up to 40 numbers, take any number their XOR and >=k are a viable option and ask how many feasible options.

Analysis: Dp[now][j] Indicates the current number of this value, then the transfer equation is dp[now][j] = Dp[pre][j] + dp[pre][j^a[i]]. Because of A^b=c's words, c^b=a, so j^a[i] can be transferred to the state of J through XOR or A[i]. You can then compress it with a scrolling array.

The code is as follows:

1#include <stdio.h>2#include <algorithm>3#include <string.h>4 using namespacestd;5typedefLong Longll;6 7 Const intLim =1<< -;8 9 intn,k;Ten inta[ -]; Onell dp[2][lim]; A  - intMain () - { the     intT;SCANF ("%d",&T); -      for(intKase=1; kase<=t;kase++) -     { -scanf"%d%d",&n,&k); +          for(intI=1; i<=n;i++) scanf ("%d", A +i); -          +Memset (DP,0,sizeof(DP)); Adp[0][0] =1; at         intnow =0; -          for(intI=1; i<=n;i++) -         { -now =1-Now ; -              for(intj=0; j<lim;j++) -             { inDP[NOW][J] = dp[1-NOW][J] + dp[1-now][j^A[i]]; -             } to         } +ll ans =0; -          for(inti=k;i<lim;i++) ans + =Dp[now][i]; theprintf"Case #%d:%i64d\n", Kase,ans); *     } $}

HDU 5119 Happy Matt friends--(backpack DP)

Related Article

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.