zoukankan      html  css  js  c++  java
  • 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, A1,...,An. 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 ai (0<=ai<=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.  

  • 相关阅读:
    回归模型与房价预测
    朴素贝叶斯应用:垃圾邮件分类
    编程实现朴素贝叶斯分类算法
    朴素贝叶斯分类算法
    K-means算法应用:图片压缩
    第八次作业
    第六次作业
    numpy数据集练习
    第五次作业
    中文词频统计
  • 原文地址:https://www.cnblogs.com/acvc/p/3914813.html
Copyright © 2011-2022 走看看