题目传送门

 /*
题意:将字符串分割成一个全排列
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. ArcGIS Engine 10.2 如何发布服务

    http://blog.csdn.net/arcgis_all/article/details/17376397 1 ArcGIS Engine 10.2 如何发布服务 ArcGIS Engine的代 ...

  2. Hadoop在window上运行 user=Administrator, access=WRITE, inode="hadoop"

    win7下eclipse中错误的详细描述如下: org.apache.hadoop.security.AccessControlException: org.apache.hadoop.securit ...

  3. [NPM] Create a new project using the npm init <initializer> command

    Historically, the npm init command was solely use to create a new package.json file. However, as of ...

  4. 最新Bootstrap手册

    http://www.jqhtml.com/bootstraps-syntaxhigh/index.html

  5. Infrastructure for container projects.

    Linux Containers https://linuxcontainers.org/

  6. mysql07---主从复制

    mysql主从复制,replication,(可以一主多从,不可一从多主) 原理: 主从分离,最少2台服务器.主服务器里面的数据,要在从服务器里面都有一份. 把主服务器的所有insert,update ...

  7. mongodb07---用户权限

    用户管理: 注意: 添加用户后,我们再次退出并登陆,发现依然可以直接读数据库? 原因: mongodb服务器启动时, 默认不是需要认证的. 要让用户生效, 需要启动服务器时,就指定 --auth 选项 ...

  8. 关于数论【polya计数法】

    可以预见数论推公式是有多么蛋疼. 让我简明扼要的讲讲吧(多都说不出来,毕竟才做了两道题)其实呢,这个算法应该归入群论,有个有用的东西:置换群,它表示一个集合包括很多的置换.先讲讲置换吧:↓(这是个置换 ...

  9. spring各个jar作用

    spring.jar --->包含完整发布模块的单个jar,但是不包括mock.jar,aspects.jar,spring-porltet.jar,spring-hibernate2.jar ...

  10. ssh配置无密码登录

    1.在master机器上生成公钥: [root@master ~]# ssh-keygen -t rsa    注:一直按enter键就可以生成了 Generating public/private ...