UVALive - 5844
Sample Input
2
3
mississippi
nni55i55ippi
2
foobar
|=o08ar
Sample Output
1
0
/**
题意:给出一个normal串,一个leet串,看能否符合关系的映射
做法:dfs 将两个串进行匹配注意初始化
**/
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#define maxn 110
using namespace std;
char ch[maxn];
char ch1[maxn];
char alp[][];
char c[];
int dfs(int k,int a,int b,int len,int len1)
{
if(a == len && b == len1) return ;
if(a == len || b == len1) return ;
for(int i=; i<k; i++)
{
if(b+i<len1)
{
memset(c,'\0',sizeof(c));
for(int j=; j<=i; j++)
{
c[j] = ch1[b+j];
}
bool isok = false;
if(strcmp(alp[ch[a]-'a'],"") == ) ///当前字母还没有匹配
{
isok = true;
strcpy(alp[ch[a]-'a'],c);
}
if(isok || (strcmp(alp[ch[a]-'a'] ,c) == ))
{
if(dfs(k,a+,b+i+,len,len1)) return ;
}
if(isok)
{
strcpy(alp[ch[a]-'a'],""); ///回溯
}
}
}
return ;
}
int main()
{
// freopen("in1.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
int k;
scanf("%d",&k);
memset(alp,'\0',sizeof(alp));
scanf("%s %s",ch,ch1);
int len = strlen(ch);
int len1 = strlen(ch1);
int tt = ; tt = dfs(k,,,len,len1);
printf("%d\n",tt);
}
return ;
}
UVALive - 5844的更多相关文章
- UVALive 5844 dfs暴力搜索
题目链接:UVAive 5844 Leet DES:大意是给出两个字符串.第一个字符串里的字符可以由1-k个字符代替.问这两个字符串是不是相等.因为1<=k<=3.而且第一个字符串长度小于 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
- UVALive 6948 Jokewithpermutation dfs
题目链接:UVALive 6948 Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...
随机推荐
- mysql初识(5)
将mysql数据库内的表导出为execel格式文件: 方法1:mysql命令:select * into outfile '/tmp/test.xls' from table_name;(需要注意的是 ...
- iOS-tableViewCell创建时添加一些动画
有时候因为项目的需要,给tableView添加一些动画: cell.layer.transform = CATransform3DMakeScale(); [UIView animateWithDur ...
- 传统IT七大职业的云计算转型之路
毫无疑问,对于那些传统IT技术--企业架构师.系统管理者.测试验收工程师或者网络工程师等开发人员骑身到云计算行业不仅是大势所趋,也能为其带来工作的保证,薪酬也更加丰厚. 如今,企业上云已经成为不可阻挡 ...
- 我的python计划
一直想学习一种脚本语言.现在主流的脚本语言,比较先接触的是python 刚开始了解了一下python,感觉挺适合自己的感觉,学习了一段时间,之中感觉,就好象C++一样,把面向对象和面向过程编程结合了起 ...
- Android Service的分类详解
按照启动方式分类 谷歌官网对Service的分类 Service根据启动方式分为两类:Started和Bound.其中,Started()是通过startService()来启动,主要用于程序内部使用 ...
- 使用HTML5的JavaScript选择器操作页面中的元素
<!doctype html><html lang="en"> <head> <meta charset="UTF-8& ...
- AtCoder 神题汇总
记录平时打 AtCoder 比赛时遇到的一些神题. Tenka1 Programmer Contest 2019 D Three Colors 题目大意 有 $n$ 个正整数 $a_1, a_2,\d ...
- 【题解】HAOI2012高速公路
一节政治课的结果……推式子+推式子+推式子…… 首先注意到一个区间里面,选择(x, y)和(y, x)的费用是一样的.所以我们把这两种情况合为一种,那么现在询问的区间为(l, r),则一共的情况就有 ...
- [Leetcode] add binary 二进制加法
Given two binary strings, return their sum (also a binary string). For example,a ="11"b =& ...
- Codeforces Round #523 (Div. 2) A. Coins
A. Coins 题目链接:https://codeforc.es/contest/1061/problem/A 题意: 给出n和s,要在1-n中选数(可重复),问最少选多少数可以使其和为s. 题解: ...