HDU 4945 (dp+组合数学)

2048

Problem Description
Teacher Mai is addicted to game 2048. But finally he finds it's too hard to get 2048. So he wants to change the rule:

You are given some numbers. Every time you can choose two numbers of the same value from them and merge these two numbers into their sum. And these two numbers disappear meanwhile.
  
If we can get 2048 from a set of numbers with this operation, Teacher Mai think this multiset is good.

You have n numbers, A 1,...,A n. Teacher Mai ask you how many subsequences of A are good.

The number can be very large, just output the number modulo 998244353.
 

Input
There are multiple test cases, terminated by a line "0".

For each test case, the first line contains an integer n (1<=n<=10^5), the next line contains n integers a i (0<=a i<=2048).
 

Output
For each test case, output one line "Case #k: ans", where k is the case number counting from 1, ans is the number module 998244353.
 

Sample Input
 
  
4 1024 512 256 256 4 1024 1024 1024 1024 5 1024 512 512 512 1 0
 

Sample Output
 
  
Case #1: 1 Case #2: 11 Case #3: 8

 

 

 题意: 给出一些数字,满足的是相同的数字才能合并,然后求出最后合并完数字能产生2048的序列。

 

sl : 一看就知道是dp了怎么dp呢,好多种情况呢。。  首先考虑dp【i】【j】 为前 2^0,2^1,......2^i 个数字 最多得到 j 个 2^i  的 集合的个数。

第i 个数字可选可不选,然后  1 不选第  i种数字 。则 2^i只能由前面的数字转移过来 。并且个数变为原来的一半。 所以 dp[i][j/2] =dp[i][j/2] +d[i-1][j];

如果选 第 i 个数字 那么 可以加上以前的数字转移过来的和当前选的数字  所以  dp【i】【j/2+k】=dp【i】【j/2+k】+d[i-1][j];  最后我们可以从1024

过渡到2048 但是如果2048存在就变成了可选可不选,搞一下组合数就行。  最后我们在乘上不相关的数字的组合数就行了。。。果然是神dp.  

 

转载于:https://www.cnblogs.com/acvc/p/3914813.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值