困惑有一条线,宣布这种阵列
问题描述:
的:pair <int, int> approach[1 << 18][17]
我不知道什么是该声明的含义是:方法[1 < < 18] [17] ;
任何人都可以帮忙吗? thnks提前
答
在这种情况下,<<
是左移位运算符。 1 << 18
表示采用1
的二进制表示并将其左移18位。这是2 (2表示电源18或262144
)。所以,你必须对一个非常大的二维数组:
pair <int, int> approach[262144][17];
答
<<
是位左移运算符。
所以1 << 18
是一个整数常量值为2 。
答
它只是意味着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");