【日后练手】(非解题)

拓扑排序+DFS(POJ1270)

#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<queue>
#include <vector>
#include<map>
#include<stack>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<algorithm>
using namespace std;
#define LL long long
#define PI acos(-1.0)
#define ING 0x7fffffff
#define INF 0x3f3f3f3f
#define DA 100005
#define N 1010
bool ma[40][40];
int pre[40];
map<char,int>gg;
int rsk;
char ans[40];
char da[30]; void tuopu(int sum)
{
if(sum==rsk)
{
printf("%s\n",ans);
return;
}
for(int i=0;i<rsk;i++)
{
if(pre[i]==0)
{
pre[i]--;
ans[sum]=da[i];
for(int j=0;j<rsk;j++)
{
if(ma[i][j])
{
pre[j]--;
}
}
tuopu(sum+1);
pre[i]++;
for(int j=0;j<rsk;j++)
{
if(ma[i][j])
pre[j]++;
}
}
}
} int main()
{
char c;
char s1[55];
char s[55]; while(gets(s1))
{ int flat=0;
int lg=strlen(s1);
int num=0;
for(int i=0;i<lg;i++)
{
if(s1[i]>='a'&&s1[i]<='z')
da[num++]=s1[i];
}
// da[num]='\0';
rsk=num; sort(da,da+num); for(int i=0;i<num;i++)
gg[da[i]]=i; gets(s);
int len=strlen(s);
int j1,j2; memset(pre,0,sizeof(pre));
memset(ma,0,sizeof(ma)); for(int i=0;i<len;i++)
{
if(s[i]>='a'&&s[i]<='z')
{
if(flat==0)
{
j1=s[i];
flat=1;
}
else
{
j2=s[i];
ma[gg[j1]][gg[j2]]=1;
pre[gg[j2]]++;
flat=0;
}
}
}
memset(ans,0,sizeof(ans));
tuopu(0);
printf("\n");
}
return 0;
}

拓扑排序+DFS(POJ1270)的更多相关文章

  1. ACM/ICPC 之 拓扑排序+DFS(POJ1128(ZOJ1083)-POJ1270)

    两道经典的同类型拓扑排序+DFS问题,第二题较第一题简单,其中的难点在于字典序输出+建立单向无环图,另外理解题意是最难的难点,没有之一... POJ1128(ZOJ1083)-Frame Stacki ...

  2. 拓扑排序-DFS

    拓扑排序的DFS算法 输入:一个有向图 输出:顶点的拓扑序列 具体流程: (1) 调用DFS算法计算每一个顶点v的遍历完成时间f[v] (2) 当一个顶点完成遍历时,将该顶点放到一个链表的最前面 (3 ...

  3. Ordering Tasks(拓扑排序+dfs)

    Ordering Tasks John has n tasks to do. Unfortunately, the tasks are not independent and the executio ...

  4. HDU 5438 拓扑排序+DFS

    Ponds Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Sub ...

  5. POJ1128 Frame Stacking(拓扑排序+dfs)题解

    Description Consider the following 5 picture frames placed on an 9 x 8 array.  ........ ........ ... ...

  6. poj1270Following Orders(拓扑排序+dfs回溯)

    题目链接: 啊哈哈.点我点我 题意是: 第一列给出全部的字母数,第二列给出一些先后顺序. 然后按字典序最小的方式输出全部的可能性.. . 思路: 整体来说是拓扑排序.可是又非常多细节要考虑.首先要按字 ...

  7. Codeforces Round #292 (Div. 2) D. Drazil and Tiles [拓扑排序 dfs]

    传送门 D. Drazil and Tiles time limit per test 2 seconds memory limit per test 256 megabytes Drazil cre ...

  8. 拓扑排序/DFS HDOJ 4324 Triangle LOVE

    题目传送门 题意:判三角恋(三元环).如果A喜欢B,那么B一定不喜欢A,任意两人一定有关系连接 分析:正解应该是拓扑排序判环,如果有环,一定是三元环,证明. DFS:从任意一点开始搜索,搜索过的点标记 ...

  9. CodeForces-1217D (拓扑排序/dfs 判环)

    题意 https://vjudge.net/problem/CodeForces-1217D 请给一个有向图着色,使得没有一个环只有一个颜色,您需要最小化使用颜色的数量. 思路 因为是有向图,每个环两 ...

随机推荐

  1. leetCode 65.Valid Number (有效数字)

    Valid Number  Validate if a given string is numeric. Some examples: "0" => true " ...

  2. OSI七层模型详解(转)

    OSI 七层模型通过七个层次化的结构模型使不同的系统不同的网络之间实现可靠的通讯,因此其最主要的功能就是帮助不同类型的主机实现数据传输 . 完成中继功能的节点通常称为中继系统.在OSI七层模型中,处于 ...

  3. bsp开发之驱动开发

    驱动程序是可以管理虚拟设备或者物理设备,协议,服务等得软件模块,操作系统仅仅有通过驱动程序才干訪问硬件.针对windows ce开发设备驱动.就是通过platform builder创建一个新的平台, ...

  4. Intel processor brand names-Xeon,Core,Pentium,Celeron----Pentium

    http://en.wikipedia.org/wiki/Pentium Pentium From Wikipedia, the free encyclopedia     This article ...

  5. 使用脚本删除ios工程中未使用图片

    使用脚本删除ios工程中未使用图片 最近在读唐巧大神的<iOS开发进阶>,学到了一个大招:使用脚本删除ios中未使用的图片(纸书上有点小问题,参考github上的issue:使用脚本删除i ...

  6. 文本分析实例---QQ聊天记录分析

    对QQ聊天记录进行分析,由于每天产生的聊天记录比較多,所以选取的是从2月份整月的聊天记录数据.分析要产生的结果有三个,聊天记录中发消息的人前top15.统计24小时时间段那个时间段发贴人最多,还有对消 ...

  7. HDOJ1002

    #include <iostream>#include<stdio.h> using namespace std;int main(){ int T, count_T; cha ...

  8. 【POJ3740】Easy Finding DLX(Dancing Links)精确覆盖问题

    题意:多组数据,每组数据给你几行数,要求选出当中几行.使得每一列都有且仅有一个1.询问是可不可行,或者说能不能找出来. 题解:1.暴搜.2.DLX(Dancing links). 本文写的是DLX. ...

  9. 用Delphi7 调用.NET 2.0的WebService 所要注意的问题(Document格式和UTF8编码)

    Delphi7 调用VS.NET 2005开发的基于.NET 2.0的WebService时发生了错误.查阅资料 http://www.community.borland.com/article/bo ...

  10. c语言基本函数

    1. 用宏定义写出swap(x,y) #define swap(x, y) x = x + y; y = x - y; x = x - y; 2.数组a[N],存放了1至N-1个数,其中某个数重复一次 ...