Words from Cubestime limit:unknown msmemory limit:65536kbthis problem would be judged onCodeforcesgym. Original id:100735h
64-bit integer IO format: %i64d Java class name: (any)
Informikas was cleaning he 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 has make any word he could think of using these cubes. He is not sure on that so now, because some of the cubes has been lost.
Informikas have already come up with a word he would like to make. Could him by saying if the word can is built from the cubes in the drawer?
Input
On the first line of input there is a string S, consisting of lowercase 中文版 letters, and an integer C4>n (4≤| S| ≤20, 1≤ N ≤100), haven Word Informikas want to build and the number of cubes. On the every of the following N Lines there is 6 characters. Every of those characters is either a lowercase 中文版 letter or a digit.
It is guaranteed, the string S consists only of lowercase Chinese letters.
Output
Output one word, either "YES", if the word can be built using given cubes, or "NO" otherwise.
Sample InputInput
Dogs 4
D 1 W e 7 9
o 2 h a v E
G 3 c 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
SourceKTU Programming Camp (Day 1) Problem solving: Maximum match, Hungarian algorithm
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN = the;4 CharSTR[MAXN];5 intN,LINK[MAXN];6 BOOLW[MAXN][MAXN],USED[MAXN];7 BOOLMatchintu) {8 for(inti =0; I < n; ++i) {9 if(Used[i] | |!w[u][i])Continue;TenUsed[i] =true; One if(Link[i] = =-1||match (Link[i])) { ALink[i] =u; - return true; - } the } - return false; - } - intMain () { + while(~SCANF ("%s", str)) { -scanf"%d",&n); +Memset (W,false,sizeofW); A Chartmp[ -]; at for(inti =0; I < n; ++i) { - for(intj =0; J <6; ++j) { -scanf"%s", TMP); - for(intK =0; STR[K]; ++k) - if(Str[k] = = tmp[0]) W[k][i] =true; - } in } -memset (link,-1,sizeofLink); to intRET =0; + for(inti =0; I < -; ++i) { -memset (Used,false,sizeofused); the if(Match (i)) + +ret; * } $printf"%s\n", strlen (str) = = ret?"YES":"NO");Panax Notoginseng } - return 0; the}
View Code
Codeforcesgym 100735H Words from cubes