Redian新闻
>
ARM servers get Xen hypervisor support
avatar
ARM servers get Xen hypervisor support# PDA - 掌中宝
r*y
1
大家好,我有一个coding的面试题, 求大家提供思路:
大意是: 有两种长短不一样的砖, 垒砌一面任意长宽的墙, 要求是上下两层不能有砖
缝相连,问有多少种砌法? 详细英文叙述见下。 我能用递归算出一层的所有可能的排
列数, 但是怎么有效的排除砖缝相连的情况呢?本人非计算机专业,求帮助!多谢
Your niece was given a set of blocks for her birthday, and she has decided
to build a panel using
3”×1” and 4.5”×1" blocks. For structural integrity, the spaces between
the blocks must not line up
in adjacent rows.
There are 2 ways in which to build a 7.5”×1” panel, 2 ways to build a 7.5
”×2” panel, 4 ways to
build a 12”×3” panel, and 7958 ways to build a 27”×5” panel. How many
different ways are there
for your niece to build a 48”×10” panel? The answer will fit in a 64-bit
integer. Write a program to
calculate the answer.
The program should be non-interactive and run as a single-line command which
takes two
command-line arguments, width and height, in that order. Given any width
between 3 and 48 that
is a multiple of 0.5, inclusive, and any height that is an integer between 1
and 10, inclusive, your
program should calculate the number of valid ways there are to build a wall
of those dimensions.
Your program’s output should simply be the solution as a number, with no
line-breaks or white
spaces.
Your program will be judged on how fast it runs and how clearly the code is
written. We will be
running your program as well as reading the source code, so anything you can
do to make this
process easier would be appreciated.
Send the source code and let us know the value that your program computes,
your program’s
running time, and the kind of machine on which you ran it.
avatar
g*e
2
Among code contributors: AMD, Oracle, Fujitsu, and yes, you read it right,
Intel!
avatar
v*d
3
觉得应该用DFS做。
关于砖缝:假定从左向右砌墙。比如现在在i层,从左边边界到i-1层任意一个砖缝的距
离可以用一个数组K[]表示。当前层正在放置的砖离左边的距离应该不会和任何一个K中
元素相等。如果砌墙到右边边界不能正好放下一块砖,就放弃当前路径。
avatar
w*g
4
WTF?

★ 发自iPhone App: ChineseWeb 7.8

【在 g******e 的大作中提到】
: Among code contributors: AMD, Oracle, Fujitsu, and yes, you read it right,
: Intel!

avatar
r*y
5
谢谢。 怎么才能让效率提高呢? 比较好的算法能一秒内完成。
如果每一块砖去比较,那是不是太慢?
avatar
i*h
6
先算出垒一层的所有组合
然后算墙要几个层的组合
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。