1023 - Discovering Permutations
Time Limit: 0.5 second(s) Memory Limit: 32 MB

In this problem you have to find the permutations using the first N English capital letters. Since there can be many permutations, you have to print the first K permutations.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case contains two integers N, K (1 ≤ N ≤ 26, 1 ≤ K ≤ 30).

Output

For each case, print the case number in a line. Then print the first K permutations that contain the first N English capital letters in alphabetical order. If there are less than K permutations then print all of them.

Sample Input

Output for Sample Input

2

3 8

10 10

Case 1:

ABC

ACB

BAC

BCA

CAB

CBA

Case 2:

ABCDEFGHIJ

ABCDEFGHJI

ABCDEFGIHJ

ABCDEFGIJH

ABCDEFGJHI

ABCDEFGJIH

ABCDEFHGIJ

ABCDEFHGJI

ABCDEFHIGJ

ABCDEFHIJG

水dfs

/* ***********************************************
Author :guanjun
Created Time :2016/6/28 14:50:20
File Name :1023.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
char s[];
int n,k,num,mark;
int vis[];
void dfs(string s,int cnt){
if(cnt==n){
num++;
cout<<s<<endl;
if(num==k)mark=;
return ;
}
if(mark)return ;
for(int i=;i<n;i++){
if(!vis[i]){
vis[i]=;
dfs(s+char(i+'A'),cnt+);
vis[i]=;
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int T;
cin>>T;
for(int t=;t<=T;t++){
printf("Case %d:\n",t);
cin>>n>>k;
cle(vis);
num=mark=;
dfs("",);
}
return ;
}

Lightoj 1023 - Discovering Permutations的更多相关文章

  1. LightOJ 1023 Discovering Permutations 水题

    http://www.lightoj.com/volume_showproblem.php?problem=1023 题意:26字母全排列 思路:用next_permutation或者思维想一下都可以 ...

  2. LightOJ 1030 Discovering Gold(期望)

    Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...

  3. LightOj 1030 - Discovering Gold(dp+数学期望)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 题意:在一个1*n 的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得 ...

  4. LightOJ - 1030 Discovering Gold —— 期望

    题目链接:https://vjudge.net/problem/LightOJ-1030 1030 - Discovering Gold    PDF (English) Statistics For ...

  5. LightOJ 1030 Discovering Gold (概率/期望DP)

    题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...

  6. LightOJ 1030 Discovering Gold(期望 概率)

    正推,到达i的概率为p[i],要注意除了1和n外,到达i的概率并不一定为1 概率表达式为p[i] += p[j] / min(n - j, 6) 从j带过来的期望为exp[i] += exp[j] / ...

  7. lightoj 1023

    题意:让你输出前N个大写字母的前K个排列,按字典序,很水,直接dfs. #include<cstdio> #include<string> #include<cstrin ...

  8. LightOJ 1030 Discovering Gold

    期望,$dp$. 设$ans[i]$为$i$为起点,到终点$n$获得的期望金币值.$ans[i]=(ans[i+1]+ans[i+2]+ans[i+3]+ans[i+4]+ans[i+5]+ans[i ...

  9. LightOJ 1030 Discovering Gold 数学期望计算

    题目大意:给出长度为n的一条隧道,每个位置都有一定数量的财宝.给你一枚骰子,roll到几点就前进几步,如果即将到达的地方超过了这条隧道长度,就重新roll一次,走到n点结束.求这个过程能收获多少财宝. ...

随机推荐

  1. [BZOJ 3823]定情信物

    题面 定情信物 题解 这题主要考高中物理和数学. 首先定义 \(f[i][j]\) 表示 \(i\) 维超立方体中第 \(j\) 维元素的数量,根据实际意义,我们可以推出递推式: \(f[i][j]= ...

  2. angularjs自己总结

    1.模块 自定的directive和controller需要在同一个model下,或者另外的model depModules他了. ng-app要等于model的名字,所有的directive要在下面 ...

  3. Ubuntu安装sublime Text 3并配置可以输入中文

    使用Ubuntu系统后,想找一个顺手的编辑器,sublime作为我的首选编辑器,在安装和配置可输入中文时遇到各种个样的问题,总结一些: 1:问题: 我的系统是Ubuntu 18.04 LTS,尝试多次 ...

  4. 【Ural1297】Palindrome(后缀数组)

    题意:求一个字符串的最长回文子串 n<=1000 思路:这是一道论文题 需要注意的细节: 1.奇偶分类 2.中间的分割符与最后的附加字母都是最小值,但两者不能相同,否则height可能会出现问题 ...

  5. JS变量写到HTML页面中并修改变量值(前台处理数据序号问题)

    有时候我们在前台需要对序号进行处理,我们需要将JS变量写到页面中进行显示. 第一种方式:后台处理 第二种方式:JS中定义全局变量,然后进行显示,可以书写一个JS函数对不同的需要进行不同的替换,也就可以 ...

  6. [Bzoj3233][Ahoi2013]找硬币[基础DP]

    3233: [Ahoi2013]找硬币 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 924  Solved: 482[Submit][Status][ ...

  7. xml建模

    1.建模的由来 就是将指定的xml字符串当作对象来操作 如果说当对一个指定的xml格式字符串完成了建模操作, 好处在于,只需要调用指定的方法就可以完成预定的字符串获取: 2.建模的思路 1.分析需要被 ...

  8. win8,win10里面内置的IE浏览器网银无法输入密码

    win8,win10里面内置的IE浏览器网银无法输入密码,安装控件也没效果,部分网银直接导致IE崩溃,只需要简单设置即可解决. 方法/步骤   1 打开IE浏览器,点击右上角的小齿轮图标,在下拉菜单中 ...

  9. HOST绑定和VIP映射

    今天上线需要配置RAL,处理半天,发现是需要HOST和IP分开来配. 比如: curl -H "Host: ktvin.nuomi.com" "http://10.207 ...

  10. 随机森林、gbdt算法

    http://blog.csdn.net/songzitea/article/details/10035757 http://blog.csdn.net/holybin/article/details ...