题目传送门

 /*
题意:将字符串分割成一个全排列
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的更多相关文章

  1. dfs Gym - 100989L

    AbdelKader enjoys math. He feels very frustrated whenever he sees an incorrect equation and so he tr ...

  2. ACM: Gym 100935G Board Game - DFS暴力搜索

    Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u  Gym 100 ...

  3. Gym 100463D Evil DFS

    Evil Time Limit: 5 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Descri ...

  4. codeforces Gym 100187J J. Deck Shuffling dfs

    J. Deck Shuffling Time Limit: 2   Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

  5. CodeForces Gym 100500A A. Poetry Challenge DFS

    Problem A. Poetry Challenge Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

  6. UVALive 6948 Jokewithpermutation dfs

    题目链接:UVALive 6948  Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...

  7. Codeforces Gym 100463D Evil DFS

    Evil Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Descr ...

  8. 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 ...

  9. 【 Gym 101116K 】Mixing Bowls(dfs)

    BUPT2017 wintertraining(15) #4H Gym - 101116K 题意 给定一个菜谱,大写的单词代表混合物,小写的代表基础原料.每个混合物由其它混合物或基础原料组成,不会间接 ...

随机推荐

  1. Office EXCEL 如何将复制的一堆数据按空格断开

    1 复制粘贴一堆数据,点击数据-分类,然后点击下一步   2 一直下一步   3 最后效果如下图所示  

  2. Sql Server 导入还有一个数据库中的表数据

    在涉及到SQL Server编程或是管理时一定会用到数据的导入与导出, 导入导出的方法有多种,此处以SQL Server导入表数据为例.阐述一下: 1.打开SQL Server Management ...

  3. PHP中常见的header类型

    <?php // 使用 mime_content_type() 查看 $mimetypes=array( 'ez' => 'application/andrew-inset', 'hqx' ...

  4. malloc内存分配

    网上总结到的信息: (1) 静态分派:是在栈上分配,是由用户自己申请,是由操作系统自己释放的 动态分配:是由编译器分配,操作系统没有提供这样的机制,所以自己申请,必须自己删除! (2)你也要明确.栈的 ...

  5. HDU1251 统计难题 【trie树】

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Subm ...

  6. myeclipse配置hadoop开发环境

    1.安装Hadoop开发插件 hadoop安装包contrib/目录下有个插件hadoop-0.20.2-eclipse-plugin.jar,拷贝到myeclipse根目录下/dropins目录下. ...

  7. Koa2学习(七)使用cookie

    Koa2学习(七)使用cookie Koa2 的 ctx 上下文对象直接提供了cookie的操作方法set和get ctx.cookies.set(name, value, [options])在上下 ...

  8. how to use datatables editor

    Basic initialisation Editor is a Create, Read, Update and Delete (CRUD) extension forDataTables that ...

  9. PP-生产订单状态

    转自:http://www.cnblogs.com/mingdashu/p/5566108.html SAP系统的常见订单状态如下: ·        CRTD (创建):标识生产订单刚刚创建,此时禁 ...

  10. caioj1230: [图论补充]哈密顿路径

    保存模版 #include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> ...