Lightoj 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的更多相关文章
- LightOJ 1023 Discovering Permutations 水题
http://www.lightoj.com/volume_showproblem.php?problem=1023 题意:26字母全排列 思路:用next_permutation或者思维想一下都可以 ...
- 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 ...
- LightOj 1030 - Discovering Gold(dp+数学期望)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 题意:在一个1*n 的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得 ...
- LightOJ - 1030 Discovering Gold —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1030 1030 - Discovering Gold PDF (English) Statistics For ...
- LightOJ 1030 Discovering Gold (概率/期望DP)
题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...
- LightOJ 1030 Discovering Gold(期望 概率)
正推,到达i的概率为p[i],要注意除了1和n外,到达i的概率并不一定为1 概率表达式为p[i] += p[j] / min(n - j, 6) 从j带过来的期望为exp[i] += exp[j] / ...
- lightoj 1023
题意:让你输出前N个大写字母的前K个排列,按字典序,很水,直接dfs. #include<cstdio> #include<string> #include<cstrin ...
- 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 ...
- LightOJ 1030 Discovering Gold 数学期望计算
题目大意:给出长度为n的一条隧道,每个位置都有一定数量的财宝.给你一枚骰子,roll到几点就前进几步,如果即将到达的地方超过了这条隧道长度,就重新roll一次,走到n点结束.求这个过程能收获多少财宝. ...
随机推荐
- 【03】使用 Firebug 调试 JavaScript
[03] 使用 Firebug 调试 JavaScript 描述 Firebug是一个非常强大的工具,可以帮助您发现代码发现错误的错误并解决错误. 在此我们使用Firebug来处理Javascript ...
- FZU2102Solve equation
Problem 2102 Solve equation Accept: 881 Submit: 2065 Time Limit: 1000 mSec Memory Limit : 3276 ...
- [Go]GOPATH相关知识点
在成功安装好Go之后,执行命令 go env 就可以看到有关go的一些环境变量,其中比较关键的是GOROOT.GOPATH和 GOBIN 1.设置GOPATH环境变量有什么意义? GOPATH是指:指 ...
- [Poi2011]Meteors 题解
题目大意: 给定一个环,每个节点有一个所属国家,k次事件,每次对[l,r]区间上的每个点点权加上一个值,求每个国家最早多少次操作之后所有点的点权和能达到一个值. 思路: 整体二分(二分答案),对于每个 ...
- ZOJ - 3781 Paint the Grid Reloaded 题解
题目大意: 给一个n*m的X O构成的格子,对一个点操作可以使与它相连通的所有一样颜色的格子翻转颜色(X—>O或O—>X),问给定的矩阵最少操作多少次可以全部变成一样的颜色. 思路: 1. ...
- /etc/fstab readyonly 解决办法
阿里云主机切换地区强制升级后,“新的磁盘盘符识别为vdb1,但是在/etc/fstab中记录的挂载信息还是旧的xvdb1,导致磁盘挂载失败” 机子启动出错了. 按提示 输入 root的密码,进入以Re ...
- C#中将数字金额转成英文大写金额的函数
<span style="white-space:pre"> </span>/// <summary> /// 数字转金额大写 /// 调用示例 ...
- jsp动态页面访问报错:HTTP Status 500 - java.lang.NullPointerException,org.apache.jasper.JasperException: java.lang.NullPointerException
今天把项目导入进去一个新的项目中去结果出现了: org.apache.jasper.JasperException: java.lang.NullPointerException 错误,jsp居然访问 ...
- 牛客网暑期ACM多校训练营(第九场) A题 FWT
链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian ...
- HDU 5700 区间交
枚举起点 二分终点 树状数组check #include<iostream> #include<cstring> #include<cmath> #include& ...