随笔分类 -  组合 --- 排列与组合-排列生成

UVA 10098 Generating Fast, Sorted Permutation
摘要:// 给你字符串 按字典序输出所有排列// 要是每个字母都不同 可以直接dfs ^_^// 用前面说的生成排列算法 也可以直接 stl next_permutation#include #include #include#include #include #include #include #include using namespace std;char s[100];int n;void change(int l,int r){ while(l0&&s[i-1]>=s[i]) i--; if(!i) return false; int k=i,j=n-1; ... 阅读全文

posted @ 2014-03-16 11:10 江财小子 阅读(264) 评论(0) 推荐(0) 编辑

POJ 1146 ID Codes (UVA146)
摘要:// 求下一个排列// 如果已经是最后一个排列// 就输出 No Successor// stl 或 自己写个 生成排列 我测试了下 两个速率是一样的、只是代码长度不同/*#include #include #include#include #include #include #include #include using namespace std;char s[100];int n;int main(){ while(scanf("%s",s),strcmp(s,"#")) { n=strlen(s); if(next_permutation(s,s 阅读全文

posted @ 2014-03-16 10:40 江财小子 阅读(296) 评论(0) 推荐(0) 编辑

POJ 1833 排列
摘要:题意: 给你某个排列 求从下一个排列开始的第k个排列如果是最后一个排列 则下一个排列为1 2 3 ... n// 1 用stl 里面的 next_permutation// 2 用生成下一个排列算法// 1)从末尾开始找第一个正序 A[i-1]A[i-1]// 3)交换 A[i-1],A[j]// 4)将下标从i开始的序列翻转 #include #include #include#include #include #include #include #include using namespace std;int s[2000];int n,k;void change(i... 阅读全文

posted @ 2014-03-16 10:20 江财小子 阅读(437) 评论(1) 推荐(0) 编辑

点击右上角即可分享
微信分享提示