hdu 4068 SanguoSHA
搜索下就可以了……
代码如下:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
int p[][],n,a[],b[];
string str[],s;
bool flag,vis[],vis2[];
bool dfs2(int d)
{
int i,j;
if(d==n){
i=j=;
while(i<n&&j<n){
bool f=;
for(int k=;k<=p[b[j]][];k++)
if(p[b[j]][k]==a[i]){
f=;
break;
}
if(f) i++;
else j++;
}
if(i==n) return ;
return ;
}
for(i=;i<n;i++){
if(vis2[i]==){
vis2[i]=;
b[d]=i;
if(!dfs2(d+)) return ;
vis2[i]=;
}
}
return ;
}
bool dfs(int d)
{
int i,j;
if(d==n){
flag=;
for(i=;i<n;i++){
memset(vis2,,sizeof(vis2));
b[]=i;
vis2[i]=;
if(!dfs2()){
flag=;
break;
}
}
if(flag) return ;
return ;
}
for(i=;i<n;i++){
if(vis[i]==){
vis[i]=;
a[d]=i;
if(dfs(d+)) return ;
vis[i]=;
}
}
}
int main()
{
int t,i,j,k,ca=;
cin>>t;
while(t--){
cin>>n;
for(i=;i<n;i++)
cin>>str[i];
sort(str,str+n);
for(i=;i<n;i++){
cin>>p[i][];
for(j=;j<=p[i][];j++){
cin>>s;
for(k=;k<n;k++){
if(s==str[k]){
p[i][j]=k;
break;
}
}
}
}
for(i=;i<n;i++){
memset(vis,,sizeof(vis));
vis[i]=;
a[]=i;
if(dfs()){
break;
}
}
printf("Case %d: ",++ca);
if(i==n) puts("No");
else{
puts("Yes");
for(i=;i<n-;i++)
cout<<str[a[i]]<<' ';
cout<<str[a[i]]<<endl;
}
}
return ;
}
hdu 4068 SanguoSHA的更多相关文章
- HDU 4068
http://acm.hdu.edu.cn/showproblem.php?pid=4068 暴力枚举两个全排列,犯了若干错误,以此为鉴 #include <iostream> #incl ...
- hdu 4068 I-number【大数】
题目: http://acm.hdu.edu.cn/showproblem.php?pid=4608 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- hdu 4068 福州赛区网络赛H 排列 ***
拍的太慢了,很不满意 排完序之后,枚举自己和对手状态,若被击败,则再枚举自己下一个策略,直到可以击败对手所有的策略 #include<cstdio> #include<iostrea ...
- hdu 4068 I-number
#include<stdio.h> #include<string.h> ]; int al; int mysum() //求各位和 { ; al=strlen(a); ; i ...
- [置顶] 2013_CSUST暑假训练总结
2013-7-19 shu 新生训练赛:母函数[转换成了背包做的] shuacm 题目:http://acm.hdu.edu.cn/diy/contest_show.php?cid=20083总结:h ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- Android中BaseAdapter的基本用法和加载自定义布局!
public class MainActivity extends Activity { ListView listView = null; @Override protected void onCr ...
- EF 随机排序
/// <summary> /// 数据上下文扩展 /// </summary> public partial class dbDataContext : IUnitOfWor ...
- golang处理错误的艺术
golang中关键API的调用都会在最后返回err(golang多值返回). 调用者可以选择处理, 或者不处理该err, 或原装返回给上一层的调用者. golang中的err是error类型, typ ...
- netlink
http://blog.csdn.net/zirconsdu/article/details/8569193 http://www.xuebuyuan.com/1725837.html netlink ...
- SQLite之写一个表
1.首先你需要一个路径. 获取document目录并返回数据库目录 - (NSString *)dataFilePath{ NSArray *paths = NSSearchPathForDirect ...
- MYSQL主键存在则更新,不存在则插入的解决方案(ON DUPLICATE KEY UPDATE)
经常我们使用的最简单的数据库操作就是数据的更新,删除和插入,对于批量删除和插入的方法相信大家都很清楚,那么批量更新估计有的人就不知道了,并且还有批量插入,在插入时若有主键冲突则更新的操作,这在EAV模 ...
- Call C# in powershell
How to call C# code in powershell Powershell Command Add-Type usage of Add-Type we use Add-Type -Typ ...
- Delphi 调试日子 - TLogger
这段时间又开始用delphi了,才发现我对它这么的不熟悉! 简单的而有效的调试工具 Logger 这个是“榕树下”的作品,小巧而精悍.稍微调整了一下.在需要的地方加入 {$IFDEF DEBUG} ...
- Careercup - Google面试题 - 6253551042953216
2014-05-06 01:49 题目链接 原题: Modify the following code to add a row number for each line is printed pub ...
- Keystore概念,Keytool工具使用
几个概念 keystore是一个密码保护的文件,用来存储密钥和证书(也就是说,keystore中存储的有两类型entries):这个文件(默认的)位于你的home目录,也就是你登录到操作系统的用户名的 ...