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 题意 给定一个菜谱,大写的单词代表混合物,小写的代表基础原料.每个混合物由其它混合物或基础原料组成,不会间接 ...
随机推荐
- python执行
转载:https://www.cnblogs.com/zflibra/p/4180796.html
- 【APUE】文件I/O
Linux的内核将所有外部设备都可以看做一个文件来操作.那么我们对与外部设备的操作都可以看做对文件进行操作.我们对一个文件的读写,都通过调用内核提供的系统调用:内核给我们返回一个file descri ...
- 【转】apache storm 内置的定时机制
原文:http://www.cnblogs.com/kqdongnanf/p/4778672.html ------------------------------------------------ ...
- icvSetWeightsAndClasses
/* *icvSetWeightsAndClasses *作用:给训练样本的权重和类别赋值 */ static void icvSetWeightsAndClasses( CvHaarTraining ...
- 使用JS对select标签进行联动选择
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- ZrcListView
https://github.com/zarics/ZrcListView
- Gson转换Json串为对象报java.lang.NoClassDefFoundError
解决方法: 1.右键项目 ---> properties ----> java buildpath ---> order and export 2. 勾选 gson-x.x.x.ja ...
- maximize_window fullscreen_window minimize_window
# Licensed to the Software Freedom Conservancy (SFC) under one# or more contributor license agreemen ...
- The type exists in both DLLs
2>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\c0b37647\aaceda91\Ap ...
- YTU 2893: F--Mark的双薪
2893: F--Mark的双薪 时间限制: 1 Sec 内存限制: 128 MB 提交: 230 解决: 17 题目描述 程序员 Mark 编制的 PPYU 游戏终于上线.Mark 认为自己起早 ...