2023-04-03 2024-10-05 problem 1 分钟读完 (大约115个字) 0次访问LC526. 优美的排列题目链接:526. 优美的排列 - 力扣(LeetCode) (leetcode-cn.com) 题解 常规状态压缩,(偷懒直接在测试台输入 1-15 的样例打表也可以) 参考代码 123456789101112131415161718class Solution {public: int countArrangement(int n) { int a[16][1<<n]; memset(a, 0, sizeof(a)); a[0][0] = 1; for(int i=1;i<=n;i++) { for(int j=0;j<(1<<n);j++) { for(int k=1;k<=n;k++) { if (k%i!=0&&i%k!=0) continue; if (j & (1<<(k-1))) continue; a[i][j|(1<<(k-1))] += a[i-1][j]; } } } return a[n][(1<<n)-1]; }}; LC526. 优美的排列https://blog.xiang578.com/problem/lc526.html作者Ryen Xiang发布于2023-04-03更新于2024-10-05许可协议 LeetCode, DP, bitmasks