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点结束.求这个过程能收获多少财宝. ...
随机推荐
- tomcat——大致简介和执行过程
jsp简介 JSP: JAVA Server Page 使用JAVA语言编写的一种在服务器运行的动态页面 JSP = JAVA + HTML JSP 的执行过程 1: 翻译阶段 把JSP源文件翻译成 ...
- HDU 4436 str2int
str2int Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on HDU. Original ID: 4 ...
- springcloud了解
学习springcloud 文章标题:[置顶] 史上最简单的 SpringCloud 教程 | 终章 学习地址:http://blog.csdn.net/forezp/article/details/ ...
- 虚拟机(Visual Machine)的云平台的自动伸缩扩容(auto-scaling)技术
云计算平台中允许客户依据应用的负载进行云计算资源的弹性动态伸缩(理想的情况是实现一个用多少付费多少的模型,最大限度地降低用户的运营成本) 在进行讨论之前,先对几个名词进行定义 1)客户:使用云服务的人 ...
- FastDFS+nginx+php的完整应用[转储]
FastDFS功能简介: FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负载均衡的问题.特别适合以 ...
- httpclient自动执行http的302重定向
今天debug过程中发现,httpclient会自动执行302的重定向,但是这个的前提是第一个请求是get发出的.我测试发现用post的后的302是系统不会自动redirect的..不知道到底正确不, ...
- POJ 2135 最小费用最大流 入门题
Farm Tour Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19207 Accepted: 7441 Descri ...
- Copy List with Random Pointer (Hash表)
A linked list is given such that each node contains an additional random pointer which could point t ...
- 转 asterisk拨号规则
asterisk拨号规则 一.前言 本文档以asterisk-1.4.32为基础写作而成,可能和其他版本有些区别. 二.Asterisk dialplan 基本结构 Asterisk dial ...
- Java实现网页截屏
原文:http://www.open-open.com/code/view/1424006089452 import java.awt.AWTException; import java.awt.De ...