第15课:排列枚举

潘CSP100班

2024-07-18 9:59:44
2024-08-17 18:35:15

信息与公告

1、选出有效排列:根据题目要求,排除无效排列,选出有效排列

2、算法思路:do-while + if
(1)用do-while-permutation枚举所有排列
(2)用if判断有效排列

sort(a+0,a+n);  //设置当前排列为最小排列
do  
{   
   for (int i = 0; i< n; i++) {   //处理当前排列
      if(…){  
         …
      }
   }
   cout<<endl;
} while (next_permutation(a + 0, a + n));  //向后枚举后面的排列
状态 题目 统计
旅行 0 / 9 / 9
质数排列 0 / 9 / 9
工作分配II 7 / 7 / 7
K皇后问题 0 / 7 / 7
特别的排列 0 / 6 / 6