CodeForcesGym 100735H Words from cubes
2015-09-16 10:44
239 查看
Words from cubes
Time Limit: Unknown msMemory Limit: 65536KB
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
Inputdogs 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
Output
YES
Input
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
Output
NO
Source
KTU Programming Camp (Day 1)解题:最大匹配,匈牙利算法
#include <bits/stdc++.h> using namespace std; const int maxn = 256; char str[maxn]; int n,Link[maxn]; bool w[maxn][maxn],used[maxn]; bool match(int u){ for(int i = 0; i < n; ++i){ if(used[i] || !w[u][i]) continue; used[i] = true; if(Link[i] == -1 || 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[20]; for(int i = 0; i < n; ++i){ for(int j = 0; j < 6; ++j){ scanf("%s",tmp); for(int k = 0; str[k]; ++k) if(str[k] == tmp[0]) w[k][i] = true; } } memset(Link,-1,sizeof Link); int ret = 0; for(int i = 0; i < 26; ++i){ memset(used,false,sizeof used); if(match(i)) ++ret; } printf("%s\n",strlen(str) == ret?"YES":"NO"); } return 0; }
View Code
相关文章推荐
- (大数据分析-3)HBASE Review
- 点滴感悟
- ios开发问题2—uitableviewController中如何改变tableview的位置
- 使用脚本便捷地在 Ubuntu 中安装最新 Linux 内核
- js 闭包概念
- cisco配置在线下载工具
- PHP Ajax 跨域问题最佳解决方案
- 君乐宝换奶粉方法
- android Service(一)
- 布局——线性布局、相对布局
- Android应用架构系列——ListView的模板化
- poj 3666
- html内嵌flex同时向flex页面传参实现pdf文档在线阅读
- iOS网络传输Delegate不被触发的本质原因
- 第三次作业
- 关于mock server
- 普通公司网站代码片段合辑
- 计算文字尺寸
- leetcode 070 Climbing Stairs(难易度:Easy)
- 怎样通过PDF转换器实现文档格式转换