CodeForcesGym 100735H Words from cubes
Words from cubes
This problem will be judged on CodeForcesGym. Original ID: 100735H
64-bit integer IO format: %I64d Java class name: (Any)
Informikas was cleaning his drawers while he found a toy of his childhood. Well, it's not just a toy, it's a bunch of cubes with letters and digits written on them.
Informikas remembers that he could have make any word he could think of using these cubes. He is not sure about that now, because some of the cubes have been lost.
Informikas has already come up with a word he would like to make. Could you help him by saying if the word can be built from the cubes in the drawer?
Input
On the first line of input there is a string S, consisting of lowercase English letters, and an integer N (4 ≤ |S| ≤ 20, 1 ≤ N ≤ 100) – the word Informikas want to build and the number of cubes. On the every of the following N lines there are 6 characters. Every of those characters is either a lowercase English letter or a digit.
It is guaranteed that the string S consists only of lowercase English letters.
Output
Output one word, either "YES", if the word can be built using given cubes, or "NO" otherwise.
Sample Input
dogs 4
d 1 w e 7 9
o 2 h a v e
g 3 c o o k
s 3 i e s 5
YES
banana 6
b a 7 8 9 1
n 1 7 7 7 6
a 9 6 3 7 8
n 8 2 4 7 9
a 7 8 9 1 3
s 7 1 1 2 7
NO
Source
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
char str[maxn];
int n,Link[maxn];
bool w[maxn][maxn],used[maxn];
bool match(int u){
for(int i = ; i < n; ++i){
if(used[i] || !w[u][i]) continue;
used[i] = true;
if(Link[i] == - || match(Link[i])){
Link[i] = u;
return true;
}
}
return false;
}
int main(){
while(~scanf("%s",str)){
scanf("%d",&n);
memset(w,false,sizeof w);
char tmp[];
for(int i = ; i < n; ++i){
for(int j = ; j < ; ++j){
scanf("%s",tmp);
for(int k = ; str[k]; ++k)
if(str[k] == tmp[]) w[k][i] = true;
}
}
memset(Link,-,sizeof Link);
int ret = ;
for(int i = ; i < ; ++i){
memset(used,false,sizeof used);
if(match(i)) ++ret;
}
printf("%s\n",strlen(str) == ret?"YES":"NO");
}
return ;
}
CodeForcesGym 100735H Words from cubes的更多相关文章
- 水泡动画模拟(Marching Cubes)
Marching Cubes算法是三维离散数据场中提取等值面的经典算法,其主要应用于医学领域的可视化场景,例如CT扫描和MRI扫描的3D重建等. 算法主要的思想是在三维离散数据场中通过线性插值来逼近等 ...
- Codeforces525E Anya and Cubes(双向搜索)
题目 Source http://codeforces.com/contest/525/problem/E Description Anya loves to fold and stick. Toda ...
- [saiku] 系统登录成功后查询Cubes
一.系统启动时初始化ds和conn 1.查询出目前系统拥有的Datasources和Connections放入内存中 2.比对saiku-datasources中的ds是否有新增的,如果有,创建新的d ...
- UVa 10601 (Polya计数 等价类计数) Cubes
用6种颜色去染正方体的12条棱,但是每种颜色都都限制了使用次数. 要确定正方体的每一条棱,可以先选择6个面之一作为顶面,然后剩下的四个面选一个作为前面,共有24种. 所以正方体的置换群共有24个置换. ...
- poj 1543 Perfect Cubes(注意剪枝)
Perfect Cubes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14901 Accepted: 7804 De ...
- OpenJudge 2810(1543) 完美立方 / Poj 1543 Perfect Cubes
1.链接地址: http://bailian.openjudge.cn/practice/2810/ http://bailian.openjudge.cn/practice/1543/ http:/ ...
- 组合数学(Pólya计数原理):UvaOJ 10601 Cubes
Cubes You are given 12 rods of equal length. Each of them is colored in certain color. Your task is ...
- cf492A Vanya and Cubes
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- uva 10051 Tower of Cubes(DAG最长路)
题目连接:10051 - Tower of Cubes 题目大意:有n个正方体,从序号1~n, 对应的每个立方体的6个面分别有它的颜色(用数字给出),现在想要将立方体堆成塔,并且上面的立方体的序号要小 ...
随机推荐
- [转]Dialog
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,在我们使用Android的过程中,我归纳了一 ...
- Linux学习大纲
- 网站防止用户复制的js方法
<script type="text/javascript">function stop() {return false;}document.oncontextmenu ...
- zhw大神线段树姿势
; i<; i++) tree[i][]=tree[i][]=i; ; i>=; i--) tree[i][]=tree[i+i][], tree[i][]=tree[i+i+][]; v ...
- 接口管理功能全面增强!EOLINKER EPC 5.0.9版本更新:支持LDAP用户系统、加入更多项目统计图表、强化测试/自动化测试功能等
EOLINKER EPC(Enterprise Private Cloud 企业私有云产品)已于近期发布5.0.9版本:界面全面改版.支持LDAP用户系统.加入更多项目统计图表.强化测试/自动化测试功 ...
- asp.net——根据时间,显示内容
题目: 在VS 2010中建立一个网站,命名为Lab5_1,建立时注意项目文件夹的存放位置.根据当前时间,在页面上显示早上好或下午好或晚上好,并显示相应的不同图片. 体验: 一开始看到这个题目的时候, ...
- Android sensor 系统框架 (一)
这几天深入学习了Android sensor框架,以此博客记录和分享分析过程,其中难免会有错误的地方,欢迎指出! 这里主要分析KERNEL->HAL->JNI这3层的流程.主要从以下几方面 ...
- windows下关闭进程树
关闭进程需要特定权限,如果你程序权限不够也会导致关闭进程失败.关闭进程树,需要遍历给定进程下的所有子进程,这个过程可以用并查集来做. 1.编写获取进程父进程的代码 #define ProcessBas ...
- linux启动时开启screen
编辑/etc/rc.local 添加 su - ubuntu -c 'screen -dmS ss zserver -p /etc/config'
- jboss-eap-6.2修改端口号
最近要改版一个项目,用来配合日常工作使用,需要在服务器上放多个jboss,那么就需要修改jboss的端口,如果服务器上配置了JBOSS_HOME,需要先删除,否则配置修改不会生效,会依然用老的jbos ...