TLE求助

P1088 [NOIP2004 普及组] 火星人

因为逐个位置比较会很耗时间的,假设N个数,其全排列有N!种,逐位比较扫描N位,时间复杂度 O(N!*N),非常大 next_permutation其实可以自动识别当前排列在全排列的相对位置的,所以直接对原数组接着及进行M次next_permutation就可以了 如下 ```cpp while (M-- && next_permutation(A.begin(), A.end())); ```
by Crescentrosesama @ 2023-04-26 18:29:58


@[Crescentrosesama](/user/975789) 结束后的A数组就是答案了
by Crescentrosesama @ 2023-04-26 18:30:43


|