链接:

https://codeforces.com/gym/102394/problem/F

题意:

Harbin, whose name was originally a Manchu word meaning "a place for drying fishing nets", grew from a small rural settlement on the Songhua River to become one of the largest cities in Northeast China. Founded in 1898 with the coming of the Chinese Eastern Railway, the city first prospered as a region inhabited by an overwhelming majority of the immigrants from the Russian Empire. Now, Harbin is the capital of Heilongjiang province and the largest city in the northeastern region of the People's Republic of China. It serves as a key political, economic, scientific, cultural, and communications hub in Northeast China, as well as an important industrial base of the nation.

This year, a CCPC regional contest is going to be held in this wonderful city, hosted by Northeast Forestry University. To ensure the contest will be a success and enjoyed by programmers around the country, preparations for the event are well underway months before the contest.

You are the leader of a student volunteer group in charge of making banners to decorate the campus during the event. Unfortunately, your group made a mistake and misprinted one of the banners. To be precise, the word "harbin" is missing in that banner. Because you don't have time to reprint it, the only way to fix it is to cut letters from some used old banners and paste them onto the misprinted banner. You have exactly six banners, and for some reason, you must cut exactly one letter from each banner. Then, you can arrange and paste the six letters onto the misprinted banner and try to make the missing word "harbin". However, before you start cutting, you decide to write a program to see if this is possible at all.

思路:

记录每个串的可用字符, DFS。

代码:

#include<bits/stdc++.h>
using namespace std; const int MAXN = 2e6+10; char s[6][MAXN];
int Vis[6][7];
int Use[7];
map<char, int> Mp; bool Dfs(int step)
{
//cout << step << endl;
if (step == 7)
return true;
for (int i = 0;i < 6;i++)
{
if (Use[i] == 1 || Vis[i][step] == 0)
continue;
Use[i] = 1;
if (Dfs(step+1))
return true;
Use[i] = 0;
}
return false;
} int main()
{
Mp['h'] = 1;
Mp['a'] = 2;
Mp['r'] = 3;
Mp['b'] = 4;
Mp['i'] = 5;
Mp['n'] = 6;
int t;
scanf("%d", &t);
while(t--)
{
memset(Use, 0, sizeof(Use));
memset(Vis, 0, sizeof(Vis));
for (int i = 0;i < 6;i++)
scanf("%s", s[i]);
for (int i = 0;i < 6;i++)
{
int len = strlen(s[i]);
for (int j = 0;j < len;j++)
{
if (Mp[s[i][j]] == 0)
continue;
Vis[i][Mp[s[i][j]]] = 1;
}
}
/*
for (int i = 0;i < 6;i++)
{
for (int j = 1;j <= 6;j++)
cout << Vis[i][j] << ' ';
cout << endl;
}
*/
if (Dfs(1))
puts("Yes");
else
puts("No");
} return 0;
}

最新文章

  1. HTML中的select只读
  2. 【Java】使用iText生成PDF文件
  3. AI(Adobe Illustrator)简单入门——小熊
  4. 简述JavaScript的运行机制
  5. Linux(Debian)+Apache+Django 配置
  6. Innodb_buffer_pool_pages_dirty [一个故事@MySQL DBA]MYSQL
  7. Linux脚本中使用特定JDK
  8. 微信小程序来了,小程序都能做些什么
  9. [Python]获取子线程异常信息
  10. gitlab之三: gitlab邮件通知的配置
  11. eclipse中将一个项目作为library导入另一个项目中
  12. iOS 第三方应用调用safari
  13. HyperServer 中的 SSL 支持
  14. ajax函数说明
  15. IIS 7 及以上 IIS错误页“编辑功能设置...”提示“锁定冲突”
  16. 新项目找不到Angular-cli.json文件
  17. mongo操作及相关资料
  18. windows安装ruby,DevKit安装rails,svn安装
  19. 【云安全与同态加密_调研分析(4)】云计算安全领域主要研究成果——By Me
  20. “全栈2019”Java第七十七章:抽象内部类与抽象静态内部类详解

热门文章

  1. oracle 常用sql 经典sql函数使用 sql语法
  2. Python列表生成式测试
  3. stm32片上ADC转换实验
  4. 安装python的pip库setup.py出现报错的解决过程
  5. AS3.0 位图翻转、旋转
  6. webpack css文件编译、自动添加前缀、剥离
  7. stdmap 用 at() 取值,如果 key 不存在,不好意思,程序崩溃。QMap 用 value()取值,如果 key 不存在,不会崩溃,你还可以指定默认值
  8. vue 写一个瀑布流插件
  9. 解决:error LNK1169: 找到一个或多个多重定义的符号
  10. Snort Rule Infographic