Redian新闻
>
python, 怎么能把 tree存到 memory了 ?
avatar
python, 怎么能把 tree存到 memory了 ?# Programming - 葵花宝典
g*y
1
所有数都是正数 A = a1 + a2...+ aN
求拆分A使得a1*a2*...*aN乘积最大
看了下以前的回复,都没人给出个具体的证明,那我来写一个数学的证明:
A = k * x = x + x + x ...
product = x^k = x ^(A/x) = [ x^(1/x) ] ^ A
对 x^(1/x) 取ln,再求导,得 (lnx - 1)/x^2
很明显,极值在 x = e 大概是 2.7 几,所以正数里,3最接近
然后可以递归的证明 A分解成 (3+3+...+3) + 2或4,就是最优解了
睡觉去了
avatar
e*7
2
这个4S
avatar
i*e
3
大家过节好!
祝大家明年更好 !
向大家请教一个问题请:
python, 怎么能把 一个tree structure 存到 memory了, 方便后面的程序用 ?
具体的问题是:
有一个 tree T, 有几千个nodes 和 leaves, (不是 binary tree, 每一级可以有任
意多的 children, 每个nodes 和 leaves,上面存的 information是很少的), 后续
需要不断地往它上面添加新的nodes 和 leaves, 就像下面的 pseudo code:
# add new item, return updated tree
new_T = add_new_item(T, new_item_to_a_particular_location)
# add another new item, return updated tree
new_new_T = add_new_item(new_T, new_item_2_to_a_particular_location)
# add more new items,return updated tree,...
由于python里, 没有 pointer, 怎么实现上面需要做的 ?把这个tree 在 memory 里
存起来 ?
还有别的办法吗 ?
avatar
h*e
4
你太闲了。。

【在 g*******y 的大作中提到】
: 所有数都是正数 A = a1 + a2...+ aN
: 求拆分A使得a1*a2*...*aN乘积最大
: 看了下以前的回复,都没人给出个具体的证明,那我来写一个数学的证明:
: A = k * x = x + x + x ...
: product = x^k = x ^(A/x) = [ x^(1/x) ] ^ A
: 对 x^(1/x) 取ln,再求导,得 (lnx - 1)/x^2
: 很明显,极值在 x = e 大概是 2.7 几,所以正数里,3最接近
: 然后可以递归的证明 A分解成 (3+3+...+3) + 2或4,就是最优解了
: 睡觉去了

avatar
l*8
5
200带合同
400升级
600裸机
每年都是如此吧

【在 e*******7 的大作中提到】
: 这个4S
avatar
w*g
6
你问的这个东西在python里就是dict套dict,存到文件里就是json/xml。
用simplejson把json读进来大概就是你要的东西。

【在 i*****e 的大作中提到】
: 大家过节好!
: 祝大家明年更好 !
: 向大家请教一个问题请:
: python, 怎么能把 一个tree structure 存到 memory了, 方便后面的程序用 ?
: 具体的问题是:
: 有一个 tree T, 有几千个nodes 和 leaves, (不是 binary tree, 每一级可以有任
: 意多的 children, 每个nodes 和 leaves,上面存的 information是很少的), 后续
: 需要不断地往它上面添加新的nodes 和 leaves, 就像下面的 pseudo code:
: # add new item, return updated tree
: new_T = add_new_item(T, new_item_to_a_particular_location)

avatar
c*f
7
mark
avatar
h*6
8
小学奥数啊。
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。