【问题标题】:Counting unique sets?计算独特的集合?
【发布时间】:2013-09-09 19:54:07
【问题描述】:

我正在解决这个问题:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=286&page=show_problem&problem=3268
我被卡住了,找不到任何提示。
问题:

 You will be given an integer n ( n<=10^9 ) now you have to tell how many
 distinct sets of integers are there such that each number from 1 to n can
 be generated uniquely from a set. Also sum of set should be n. eg for n=5 , one such set is:
 {1,2,2} as
 1 can be generated only by  { 1 }
 2 by { 2 }
 3 by {1,2} ( note the two 2's are indistinguishable)
 4 by {2,2}
 5 by {1,2,2}
 for generating a number each number of a set can be used only once. ie for above set
 we can't do {1,1} to generate 2 as only one 1 is there.
 Also the set {1,2,2} is equivalent to {2,1,2} ie sets are unordered.

我的做法:

 The conclusion I came to was. Let F(S,k) denote number desired sets of sum S whose 
 largest element is k.Then to construct a valid set we can take two paths from this
state.Either to F(S+k,k) or to F(2*S+1,S+1).I keep a count of how many times I come
to state where S=n(the desired sum) and do not go further if S becomes > n.This is  
clearly bruteforce which I just wrote to see if my logic was correct(which is correct)
.But this will give time limit exceed . How do I improve my approach??I have a 
feeling  it is done by dp/memoization. 

【问题讨论】:

  • 当您陈述问题时,答案总是“无限多”。问题是您忽略了源原始问题的条件之一:所有权重必须加起来为n。如果您忽略该条件,您始终可以向您的集合添加大于 n 的权重 - 例如,对于 n = 5,集合 {1,2,2,6}{1,2,2,7}{1,2,2,8} 等都可以作为好。一个始终有效的集合是采用元素1n 副本,因此我们总是有一个可以扩展的基本情况。
  • (请注意,这个问题实际上并不处理集合,而是处理传统上称为多重集或袋子的对象 - 集合传统上不允许单个元素的多个副本。)

标签: algorithm data-structures dynamic-programming counting


【解决方案1】:

这是一个已知的整数序列。

剧透:http://oeis.org/A002033

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多