LA 3907 Puzzle

Jisung is the student representative of the Department of Computer Engineering in ACM University.
A few days later, the annual festival will be held for the students in the department. He is preparing
some events for the festival. Since Jisung likes to make and solve puzzles, he decides to devise some
interesting puzzle for the festival.
The followings are the rules for the puzzle made by Jisung:
(1) The players will be given an integer n. Then they should use the first n capital letters from the
Roman alphabet. For example, if n = 4, the four characters A, B, C, and D will be used to solve
this puzzle.
(2) The players will be given s forbidden strings. No forbidden string contains another forbidden
string as a substring. The winner is the student who makes the longest string that does not
include a forbidden string as a substring.
(3) If such a longest string does not exist, i.e., if we can make arbitrarily long strings that satisfy the
above condition, or if we cannot make any string that satisfies the above condition, ‘No’ should
be answered.
For example, suppose the given number n = 2, i.e., the players can use the two characters A and
B. Assume that the forbidden strings are {AAA, AB, BA, BB}. In this case, the longest string that does
not include any of the four forbidden strings as substrings is AA. But if the given forbidden strings are
{AAA, BBB, ABAB, BBAA}, we cannot make such a longest string since arbitrarily long concatenations of
ABA, i.e., ABAABAABA . . . do not include any forbidden string.
Input
Your program is to read from standard input. The input consists of T test cases. The number of test
cases T is given in the first line of the input. Each test case starts with a line containing two integers
n (1 ≤ n ≤ 26) and s (1 ≤ s ≤ 1, 000) which represent the number of characters and the number of
forbidden strings, respectively. From the second line to (s + 1)-st line of the test case, the forbidden
strings are given one by one. The length of a forbidden string does not exceed 50.
Output
Your program is to write to standard output. Print exactly one line for each test case. Print the
longest string that does not include any forbidden string as a substring if it exists, otherwise, just print
‘No’ as output. When there exists more than one such longest string with the same length, print the
lexicographically largest string among them.
Sample Input
3
2 4
AAA
AB
BA
BB
2 4
AAA
BBB
ABAB
BBAA
3 7
AA
ABA
BAC
BB
BC
CA
CC
Sample Output
AA
No
ACBAB

时间: 2024-08-01 06:51:48

LA 3907 Puzzle的相关文章

BZOJ 3907: 网格

Description 求不跨过直线 \(y=x\) ,到达 \((n,m)\) 的方案数. Sol 组合数学+高精度. 这个推导过程跟 \(Catalan\) 数是一样的. 答案就是 \(C^{n+m}_n-C^{n+m}_{n+1}\) 自己随便化简一下就是 \(\frac {(n+m)!(n-m+1)} {(n+1)!m!}\) . 然后需要先分解下质因数,再用高精度. Code /******************************************************

hdu 5745 la vie en rose

这道题的官方题解是dp,但是可以暴力出来.改天再研究怎么dp. 暴力的时候,如果计算sum的时候,调用strlen函数会超时,可见这个函数并不是十分的好.以后能不用尽量不用. La Vie en rose Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 861    Accepted Submission(s): 461 Problem

UVa - 227 - Puzzle

给空格子上下左右的互换操作,问最后是怎样的 注意一行的最后一个若是空格,需要自己加注意读取时 操作可能分好多行,一定要读取到 0 为止 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 char map[50][50],op[1000],c,tmp; 5 int k,t,x,y,cnt; 6 bool flag; 7 void fuc() 8 { 9 flag=1; 10 for(int i=0;

让MAC OS也能使用LL LA L等LS的别名

linux下默认ll是ls -l的别名.OS X下默认不支持.习惯了linux下使用ll,我们同样也可以将习惯搬到os x下的shell中. 再当前用户家目录下新建.bash_profile文件.根据你的习惯,添加下面格式内容即可. 1 2 3 alias ll='ls -l' alias la='ls -a' alias l='ls -la' 然后执行:source .bash_profile你还可以添加你喜欢的其他别名.

HDU 5465 Clarke and puzzle Nim游戏+二维树状数组

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 269 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 克拉克是一名人格分裂患者.某一天,有两个克拉克(aa和bb)在玩一个方格游戏. 这个方格是一个n*mn∗m的矩阵,每个格子里有一

HDU 1098 Ignatius&#39;s puzzle 费马小定理+扩展欧几里德算法

题目大意: 给定k,找到一个满足的a使任意的x都满足 f(x)=5*x^13+13*x^5+k*a*x 被65整除 推证: f(x) = (5*x^12 + 13 * x^4 + ak) * x 因为x可以任意取 那么不能总是满足 65|x 那么必须是 65 | (5*x^12 + 13 * x^4 + ak) 那么就是说 x^12 / 13 + x^4 / 5 + ak / 65 正好是一个整数 假设能找到满足的a , 那么将 ak / 65 分进x^12 / 13 + x^4 / 5中得到

HDU 4708 Rotation Lock Puzzle (贪心+模拟)

Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1668    Accepted Submission(s): 530 Problem Description Alice was felling into a cave. She found a strange door with a number

Dearboy&#39;s Puzzle (poj 2308 搜索 dfs+bfs)

Language: Default Dearboy's Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1202   Accepted: 208 Description Dearboy is a game lover. Recently, he loves playing the game Lian Lian Kan. This game is played on a board with N*M grids

hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Alice was felling into a cave. She found a strange door with a number square m