【日后练手】(非解题)

拓扑排序+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. Unity3d中制作异步Loading进度条所遇到的问题

    背景 通常游戏的主场景包括的资源较多,这会导致载入场景的时间较长.为了避免这个问题,能够首先载入Loading场景.然后再通过Loading场景来载入主场景. 由于Loading场景包括的资源较少,所 ...

  2. C#语言 ArrayList集合

  3. RAC改动归档文件夹

    逐个节点改动 关闭全部节点,启动单节点(rac1)到mount状态 SQL> startup mount; 改动server參数配置 SQL> alter system set clust ...

  4. Redis 脚本及其应用

    参考:http://www.runoob.com/redis/redis-scripting.html Redis 脚本使用 Lua 解释器来执行脚本. Reids 2.6 版本通过内嵌支持 Lua ...

  5. Python开发【2.1 面向对象】

    1.面向对象概述 类(Class): 用来描述具有相同的属性和方法的对象的集合.它定义了该集合中每个对象所共有的属性和方法.对象是类的实例. 类变量:类变量在整个实例化的对象中是公用的.类变量定义在类 ...

  6. MVC Controller构造器注入

    UnityDependencyResolver 的标准写法 public class UnityDependencyResolver : IDependencyResolver {     priva ...

  7. LeetCode(27)题解:Remove Element

    https://leetcode.com/problems/remove-element/ Given an array and a value, remove all instances of th ...

  8. Python 003- 小知识汇总(更新中)

    #查询key是否存在,可以在使用未知的字典的时候使用 #-*- coding:utf-8 -*- D={'a':1,'c':3,'b':2} for key in sorted(D): print(k ...

  9. JSP JDBC 读取SQL Server 数据2

    <%-- Created by IntelliJ IDEA. User: hellohongfu Date: 2017/12/21 Time: 0:16 To change this templ ...

  10. iOS UI控件之间的关系图