lightoj 1023
题意:让你输出前N个大写字母的前K个排列,按字典序,很水,直接dfs。
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int vis[26], N, K, cnt;
void dfs(int dep, string str){
if(cnt == K) return;
if(dep == N){
cout << str << endl;
cnt ++;
return;
}
for(int i = 0;i < N;i ++){
if(!vis[i]){
vis[i] = 1;
char ch = i + 'A';
dfs(dep + 1, str + ch);
if(cnt == K) return;
vis[i] = 0;
}
}
}
int main(){
int t,CASE(0);
scanf("%d", &t);
while(t--){
cnt = 0;
memset(vis, 0, sizeof vis);
scanf("%d%d", &N, &K);
printf("Case %d:\n", ++CASE);
dfs(0, "");
}
return 0;
}
lightoj 1023的更多相关文章
- LightOJ 1023 Discovering Permutations 水题
http://www.lightoj.com/volume_showproblem.php?problem=1023 题意:26字母全排列 思路:用next_permutation或者思维想一下都可以 ...
- Lightoj 1023 - Discovering Permutations
1023 - Discovering Permutations PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory L ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- LightOj 1298 - One Theorem, One Year(DP + 欧拉)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1298 题意:给你两个数 n, p,表示一个数是由前 k 个素数组成的,共有 n 个素数 ...
- 1214 - Large Division -- LightOj(大数取余)
http://lightoj.com/volume_showproblem.php?problem=1214 这就是一道简单的大数取余. 还想还用到了同余定理: 所谓的同余,顾名思义,就是许多的数被一 ...
- LightOJ Beginners Problems 部分题解
相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's ...
- LightOJ 1341 唯一分解定理
Aladdin and the Flying Carpet Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld &a ...
- lightoj 1370 欧拉函数
A - Bi-shoe and Phi-shoe Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & % ...
随机推荐
- Android ImageButton的背景(图片)大小
使用ImageButton的background属性,而不用src属性. 然后使用width和height进行调整.
- 使用getJSON()方法异步加载JSON格式数据
使用getJSON()方法异步加载JSON格式数据 使用getJSON()方法可以通过Ajax异步请求的方式,获取服务器中的数组,并对获取的数据进行解析,显示在页面中,它的调用格式为: jQuery. ...
- [GCJ]Password Attacker
https://code.google.com/codejam/contest/4214486/dashboard#s=p0 排列组合.DP递推式,如下代码.dp[m][n]表示长度为n的字符串里有m ...
- 前台将勾选的多个属性放到一个value里面,是一个字符串,传到后台
jq function changeStreet(a){ var valk=$(a).html(); $(a).parents(".select_box").children(&q ...
- Python中itertools模块
itertools模块包含创建有效迭代器的函数,可以用各种方式对数据进行循环操作,此模块中的所有函数返回的迭代器都可以与for循环语句以及其他包含迭代器(如生成器和生成器表达式)的函数联合使用. ch ...
- jQuery好用插件
jQuery图片轮播插件(smallslider):http://fz.sjtu.edu.cn/zsw/js/smallslider/ jQuery消息通知(noty):http://www.360d ...
- Android 清除canvas 笔迹代码
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); canvas.drawLine(pointX, , event.getX(), ...
- Android 自定义ActionBar
Android 3.0及以上已经有了ActionBar的API,可以通过引入support package在3.0以下的平台引用这些API,但这儿呢,完全自定义一个ActionBar,不用引入额外ja ...
- Btrace入门到熟练小工完全指南
BTrace是神器,每一个需要每天解决线上问题,但完全不用BTrace的Java工程师,都是可疑的. BTrace的最大好处,是可以通过自己编写的脚本,获取应用的一切调用信息.而不需要不断地修改代码, ...
- hive 学习笔记——表的入门操作和命令
1.受控表(managed table)包括内部表.分区表.桶表: 1.1.分区表 创建分区表: create table banji(id INT,name STRING) partitioned ...