对声明这种数组感到困惑
Confused of declaring this kind of array
我正在阅读这个代码
有一条线路: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!<=(1<<18))。
但这个定义并没有说明这一点,让我们看看是否可以让它更清楚(希望是正确的)。
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");
相关文章:
- 无法将字符串数组声明为类成员而不是字符 (C++)
- 为什么从函数返回数组时需要将数组声明为静态数组.(C++)
- 在 c++ 中直接访问的内联数组声明
- 由于 2D 数组声明,C++ 14 中的运行时错误
- 如何将char数组声明为函数参数?或告诉我此代码中还有其他问题?
- 来自函数参数的 C++ 静态数组声明
- C++ 中的动态数组声明
- C++数组声明
- 数组声明中的错误:表达式必须具有常量值
- 程序随数组声明崩溃
- 运行时和编译时的数组声明
- C++数组声明和初始化
- 带有常量表达式的数组声明
- C ,数组声明,模板,链接器错误
- 如何用'n'维数组声明 std::vector?
- 数组声明上的编译器错误
- 这是什么数组声明
- 头文件类中的数组声明
- 节点数组声明
- 在静态数组声明中使用了两次C++常量