【发布时间】:2014-10-12 08:30:58
【问题描述】:
我在读这个code
有一行:pair <int, int> approach[1 << 18][17]
我不知道这个声明是什么意思:approach[ 1<<18 ][17];
谁能帮忙?
【问题讨论】:
我在读这个code
有一行:pair <int, int> approach[1 << 18][17]
我不知道这个声明是什么意思:approach[ 1<<18 ][17];
谁能帮忙?
【问题讨论】:
在此上下文中,<< 是位左移运算符。 1 << 18 表示取 1 的二进制表示并将其向左移动 18。这是 218(2 的 18 次方,或 262144)。所以你有一个非常大的二维数组对:
pair <int, int> approach[262144][17];
【讨论】:
<< 是位左移运算符。
所以1 << 18 是一个整数常量,其值为 218。
【讨论】:
它只是表示 2^18,2 的 18 次方。
代码缺少一些解释,唯一真正好的信息是
// SGU 502 -- Digits Permutation
嗯,关于数字排列,所以
pair <int, int> approach[1 << 18][17]
可能用于存储排列,除非排列有一些限制,否则排列的数量应该是 N! (希望N!
但定义并没有说明这一点,让我们看看我们是否可以更清楚地说明(希望是正确的)。
const int maxLength = 17;
const int maxPermutation = 1 << (maxLength+1);
pair <int, int> approach[maxPermutation ][maxLength]
static_assert(factorial(maxLength) <= maxPermutation, "approach might not be able to hold all permutations");
【讨论】: