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 题意 给定一个菜谱,大写的单词代表混合物,小写的代表基础原料.每个混合物由其它混合物或基础原料组成,不会间接 ...
随机推荐
- Teamviewer ubuntu 提示 TeamViewer Daemon is not running
http://blog.csdn.net/laohuang1122/article/details/12657343 Ubunut 12.04下面安装了Teamviewer,刚安装完启动是没有问题的, ...
- Openwrt挂载NTFS硬盘提示“只读”错误的解决方法!
Openwrt是基于Linux代码编写,只支持NTFS格式硬盘的只读权限,否则当挂载的NTFS硬盘写入超过2M左右,就会出现"error:read-only file system" ...
- ubuntu磁盘分区和挂载
- 《从0到1》读书笔记第一章"未来的挑战"第1记:把握潮流风向
这几天刚到手当前炙手可热的来自PayPal创始人Peter Thiel的<Zero to One>.中文名<从0到1>,由高玉芳翻译.中信出版社出版.由于到货时刚好有事情在忙, ...
- powershell 通过SMTP发送邮件
一直以来就用.net的方式发送邮件.由于powershell自带的方式用起来easy出错.且比較简单,近期看到一些人也反应使用中遇到麻烦. #定义函数 function sendmail($maila ...
- vue 自定义报警组件
1.自定义报警组件 Alarm.vue <!-- 报警 组件 --> <template> <div class="alarm"> <!- ...
- 在linux命令行中编译和运行java文件
同时加载编译多个jar包和java文件 在个人平常使用或者当我们把代码部署到linux服务器上的时候,我们经常需要通过命令行编译和运行java文件,网上关于这个的方法大多是通过 javac -cp f ...
- 读取本地json文件,转出为指定格式json 使用Base64进行string的加密和解密
读取本地json文件,转出为指定格式json 引用添加Json.Net 引用命名空间 using Newtonsoft.Json //读取自定目录下的json文件StreamReader sr = ...
- 一起talk C栗子吧(第一百二十一回:C语言实例--线程知识体系图)
各位看官们.大家好,上一回中咱们说的线程属性的样例.这一回咱们说的样例是:线程知识体系图.闲话休提.言归正转. 让我们一起talk C栗子吧! 我们在前面的章回中介绍了与线程相关的知识,在今天的章回中 ...
- jQuery操作Form表单元素
Web开发中常常须要操作表单,form表单元素有select.checkbox.radio.textarea.button.file.text.hidden.password等. 当中checkbox ...