HDU 4068
http://acm.hdu.edu.cn/showproblem.php?pid=4068
暴力枚举两个全排列,犯了若干错误,以此为鉴
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std ;
int n,f,m[],vis[],vis2[],temp[] ;
string str[],ans[],s[][],res[] ;
int OK()
{
int i,j,flag ;
i=j= ;
while(i<n && j<n)
{
flag= ;
for(int k= ;k<m[temp[i]] ;k++)
{
if(s[temp[i]][k]==res[j])
{
flag= ;
break ;
}
}
if(flag)j++ ;
else i++ ;
}
if(i==n)return ;
return ;
}
int ff ;
int dfs2(int cur)
{
if(cur==n)
{
if(!OK()){
ff= ;
return ;
}
}
for(int i= ;i<n && ff ;i++)
{
if(!vis2[i])
{
vis2[i]= ;
temp[cur]=i ;
dfs2(cur+) ;
vis2[i]= ;
}
}
if(ff)return ;
return ;
}
void dfs(int cur)
{
if(f)
return ;
if(cur==n)
{
ff= ;
memset(vis2,,sizeof(vis2)) ;
if(dfs2())
{
f= ;
for(int i= ;i<n ;i++)
ans[i]=res[i] ;
}
return ;
}
for(int i= ;i<n ;i++)
{
if(!vis[i])
{
vis[i]= ;
res[cur]=str[i] ;
dfs(cur+) ;
vis[i]= ;
}
}
} int main()
{
int t ;
scanf("%d",&t) ;
for(int cas= ;cas<=t ;cas++)
{
scanf("%d",&n) ;
for(int i= ;i<n ;i++)
cin >> str[i] ;
for(int i= ;i<n ;i++)
{
scanf("%d",&m[i]) ;
for(int j= ;j<m[i] ;j++)
{
cin >> s[i][j] ;
}
}
sort(str,str+n) ;
f= ;
memset(vis,,sizeof(vis)) ;
dfs() ;
printf("Case %d: ",cas) ;
if(f)
{
puts("Yes") ;
for(int i= ;i<n ;i++)
{
if(i)
{
putchar(' ') ;
}
cout << ans[i] ;
}
putchar('\n') ;
}
else
puts("No") ;
}
return ;
}
HDU 4068的更多相关文章
- 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 SanguoSHA
搜索下就可以了…… 代码如下: #include<iostream> #include<cstring> #include<cstdio> #include< ...
- 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 ...
随机推荐
- PHP接收json格式的POST数据
/** * 获取 post 参数; 在 content_type 为 application/json 时,自动解析 json * @return array */ private function ...
- namenode 问题小记
问题1:namenode进程故障 Namenode挂掉,Namenode gc日志里面YGC报错promotion failed 现象描述 NameNode进程挂掉,Namenode gc日志里面YG ...
- 29张截图-全新安装CentOS7.5-超详细!
目录 全新安装CentOS7.5 配置虚拟机 调整网卡名称 配置时区,分区,关闭安全工具 配置网络参数 配置root账户密码 参考链接 全新安装CentOS7.5 可以到这里下载镜像https://m ...
- 全自动照片美化软件Photolemur mac特别版
今天小编为大家带来的是世界上首个支持全自动照片美化的软件Photolemur mac特别版.Photolemur中文特别版采用了全新的人工智能AI系统,它能够全自动智能的对您的照片进行曝光.亮度.降噪 ...
- Tomcat环境变量设置
tomcat环境变量配置 CATALINA_HOME:D:\server\apache-tomcat-8.5.32 //安装目录 CATALINA_BASE:D:\server\ap ...
- Qt的信号和槽是如何工作的
用Qt做过开发的朋友,不知道是否曾为下面这些问题疑惑过:我们知道Qt是基于C++的,Qt写的代码最终还是要由C++编译器来编译,但是我们的Qt代码中有很多C++里没有的关键字,比如slots\sign ...
- fileupload上传文件时带参数
var userID = ""; $('#picture').fileupload({ url: "http://localhost:35708/Handler/File ...
- Centos75 安装 postgresql11
切换到root账户, #安装yum 源 yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_6 ...
- [置顶] SNMP协议详解<三>
在上篇文章中,说到了SNMPv3主要在安全性方面进行了增强,采用USM(基于用户的安全模型)和VACM(基于视图的访问控制模型)技术.下面我们就主要讲解SNMPv3的报文格式以及基于USM的认证和加密 ...
- 20145221 《Java程序设计》第一周学习总结
20145221 <Java程序设计>第一周学习总结 教材学习内容总结 第一周内容已在假期完成,详见博客: Hello Java! 开源中国的代码托管 代码调试中的问题和解决过程 第一周内 ...