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个面分别有它的颜色(用数字给出),现在想要将立方体堆成塔,并且上面的立方体的序号要小 ...
随机推荐
- 【转】webview的几个问题
我们在native与网页相结合开发的过程中,难免会遇到关于WebView一些共通的问题.就我目前开发过程中遇到的问题以及最后得到的优化方案都将在这里列举出来.有些是老生常谈,有些则是个人摸索得出解决方 ...
- poj1200Crazy Search(hash)
题目大意 将一个字符串分成长度为N的字串.且不同的字符不会超过NC个.问总共有多少个不同的子串. /* 字符串hash O(n)枚举起点 然后O(1)查询子串hash值 然后O(n)找不一样的个数 ...
- 调取easyui -windows 返回值问题
//-------------------------------------------------------------------------------------------------- ...
- HTML--文本输入框、密码输入框
当用户要在表单中键入字母.数字等内容时,就会用到文本输入框.文本框也可以转化为密码输入框. 语法: <form> <input type="text/password&qu ...
- PHP 在线 编辑 解析
http://www.w3schools.com/php/default.asp http://www.w3schools.com/php/showphp.asp?filename=demo_s ...
- C#用Microsoft.Office.Interop.Word进行Word转PDF的问题
之前用Aspose.Word进行Word转PDF发现'\'这个字符会被转换成'¥'这样的错误,没办法只能换个方法了.下面是Microsoft.Office.Interop.Word转PDF的方法: p ...
- js基础---object对象
//**********************************复杂JSON举例**************************************** var Jsondata={d ...
- Android Studio 关于build.gradle配置问题
当导入一个Android Project时,会出现很多版本的问题,导入前先删除 .idea文件 .gradle文件 ,gradle文件(与.gradle区分,导入时Android Studio会提示重 ...
- ORA-02068,ORA-03135错误解决方法
今天查看了下ERP DB服务器 alter_<SID>.log日志,发现有个错误 Sat Sep 14 14:49:42 CST 2013 Error 2068 trapped in 2P ...
- 移动web——touch事件应用
基本概况 1.touch事件在移动端被用来代替click事件,因为click事件的触发会延迟影响了用户体验 2.touch事件还可以与translate构成吸附效果 3.现行有一种排版方式是左边宽度是 ...