HDU-5119 Happy Matt Friends (backpack DP, Recursive enumeration)

Source: Internet
Author: User

Test instructions: n items, the weight of the article I is Ki, select some items to make them different or not less than M, how many options

Data range: 1 <= n <= 40,0 <= m <= 1e6

Idea: In fact, is a request for a backpack, MX to open more than 1e6, not scrolling array can also pass.

The old routine set Dp[i][j] for the first I item xor, dp[i][j] = Dp[i-1][j] + dp[i-1][j^a[i]], and finally sum the values of dp[n][m above]

1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineLL Long Long5 using namespacestd;6 7 Const intMX =1<< -;8 inta[ -];9LL dp[ -][mx+Ten];Ten  One intMain () { A     intT, Kase =0; -scanf"%d", &t); -      while(t--){ the         intN, M; -Memset (DP,0,sizeofDP); -LL ans =0; -scanf"%d%d", &n, &m); +          for(inti =1; I <= N; i++) -scanf"%lld", &a[i]); +dp[0][0] =1; A          for(inti =1; I <= N; i++) at              for(intj =0; J <= MX; J + +) -DP[I][J] = dp[i-1][J] + dp[i-1][j^A[i]]; -          for(inti = m; i < MX; i++) -Ans + =Dp[n][i]; -printf"Case #%d:%lld\n", ++Kase, ans); -     } in     return 0; -}

HDU-5119 Happy Matt Friends (backpack DP, Recursive enumeration)

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.