DFS Gym 100553J Jokewithpermutation
/*
题意:将字符串分割成一个全排列
DFS:搜索主要在一位数和两位数的处理,用d1, d2记录个数,在不饱和的情况下,两种都试一下
DFS还是写不来,难道是在家里懒?
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; const int MAXN = 1e2 + ;
const int INF = 0x3f3f3f3f;
char s[MAXN];
bool vis[];
int ans[];
int len, tot, n1, n2; bool DFS(int d1, int d2, int p, int cnt)
{
if (cnt == tot) return true;
if (d1 < n1)
{
int x = s[p] - '';
if (x != && !vis[x])
{
vis[x] = true; ans[cnt+] = x;
if (DFS (d1+, d2, p+, cnt+)) return true;
vis[x] = false;
}
}
if (d2 < n2)
{
int x = (s[p] - '') * + (s[p+] - '');
if (x >= && x <= tot && !vis[x])
{
vis[x] = true; ans[cnt+] = x;
if (DFS (d1, d2+, p+, cnt+)) return true;
vis[x] = false;
}
} return false;
} int main(void) //Gym 100553J Jokewithpermutation
{
// freopen ("J.in", "r", stdin);
freopen ("joke.in", "r", stdin);
freopen ("joke.out", "w", stdout); while (scanf ("%s", s + ) == )
{
memset (vis, false, sizeof (vis));
len = strlen (s + );
tot = (len + ) / ;
if (tot <= )
{
for (int i=; i<=len; ++i)
{
printf ("%c%c", s[i], (i==len) ? '\n' : ' ');
}
}
else
{
n1 = ; n2 = tot - ;
DFS (, , , );
for (int i=; i<=tot; ++i)
{
printf ("%d%c", ans[i], (i==tot) ? '\n' : ' ');
}
}
} return ;
}
DFS Gym 100553J Jokewithpermutation的更多相关文章
- dfs Gym - 100989L
AbdelKader enjoys math. He feels very frustrated whenever he sees an incorrect equation and so he tr ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
- Gym 100463D Evil DFS
Evil Time Limit: 5 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Descri ...
- codeforces Gym 100187J J. Deck Shuffling dfs
J. Deck Shuffling Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...
- CodeForces Gym 100500A A. Poetry Challenge DFS
Problem A. Poetry Challenge Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- UVALive 6948 Jokewithpermutation dfs
题目链接:UVALive 6948 Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...
- Codeforces Gym 100463D Evil DFS
Evil Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Descr ...
- Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】
E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard inp ...
- 【 Gym 101116K 】Mixing Bowls(dfs)
BUPT2017 wintertraining(15) #4H Gym - 101116K 题意 给定一个菜谱,大写的单词代表混合物,小写的代表基础原料.每个混合物由其它混合物或基础原料组成,不会间接 ...
随机推荐
- 【APUE】文件I/O
Linux的内核将所有外部设备都可以看做一个文件来操作.那么我们对与外部设备的操作都可以看做对文件进行操作.我们对一个文件的读写,都通过调用内核提供的系统调用:内核给我们返回一个file descri ...
- 【转】ubuntu 下安装mongodb php 拓展的方法
按照上面的方法安装成功之后,写一个 mongodb 的php测试脚本,用来测试是否可以 正确连接上mongodb ,并查询结果. 参考:http://php.net/manual/en/class.m ...
- es5~es6
1.用箭头函数减少代码(相信你在Vue已经看到了) ES5: function greetings (name) { return 'hello ' + name } ES6: const greet ...
- js 终止执行的实现方法
终止JS运行有如下几种可能: 1.终止函数的运行的方式有两种 (1)在函数中使用return,则当遇到return时,函数终止执行,控制权继续向下运行 (2)在函数中使用try-catch异常处理,需 ...
- Android5.0(lollipop)新特性介绍(一)
今年6月的Google I/O大会上.Android L的初次见面我相信让会让非常多android粉丝有些小激动和小期待.当然作为开发人员的我来说,激动不言而喻,毕竟这是自08年以来改变最大的一个版本 ...
- Codeforces Beta Round #22 (Div. 2 Only) E. Scheme dfs贪心
E. Scheme To learn as soon as possible the latest news about their favourite fundamentally new ope ...
- JAVA泛型类
泛型是JDK 5.0后出现新概念,泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数.这种参数类型可以用在类.接口和方法的创建中,分别称为泛型类.泛型接口.泛型方法. 泛型类引入的好处不 ...
- hadoop3 无法启动 查找内存消耗原因
[root@hadoop3 hadoop]# xloStarting namenodes on [hadoop3]上一次登录:三 12月 27 15:07:11 CST 2017pts/24 上had ...
- 内部消息 微软中国云计算 内測Azure免费账号 赶紧申请 错过不再有
内部消息 微软中国云计算 顶级内測Azure免费账号 火热申请 过期不再有! 微软MSDN俱乐部 29754721, [一大波Azure免费账号来袭]Windows Azure再次开启示放免费试用账 ...
- 网络驱动移植之net_device结构体及其相关的操作函数
内核源码:Linux-2.6.38.8.tar.bz2 在Linux系统中,网络设备都被抽象为struct net_device结构体.它是网络设备硬件与上层协议之间联系的接口,了解它对编写网络驱动程 ...