【日后练手】(非解题)

拓扑排序+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. [WASM Rust] Use the js-sys Crate to Invoke Global APIs Available in Any JavaScript Environment

    js-sys offers bindings to all the global APIs available in every JavaScript environment as defined b ...

  2. SolidEdge 装配体中如何快速的搞定一个面上所有螺丝 如何在装配体上进行阵列

    1 点击"规则排列" 选择要排列的螺丝   2 选择被规则排列的架子   3 选择所有的圆孔(鼠标滑到任意圆孔位置,左键单击即可选中所有圆孔)   4 选择参考的基准孔(已经上了螺 ...

  3. docker nginx镜像+phpfpm 镜像 组合配置 搭建 PHP+nginx 环境

    前言 在以往的容器环境部署中 运行环境 我们通常把 类似 apache nginx php 等 打包在一个镜像中 起一个容器. 这样做的好处是 方便 简单. 不便的地方是 如果PHP 需要扩展新的 相 ...

  4. eclipse使用正则表达式查找文件内容

    今天有个需求,查找工程中包含汉字的所有文件,随即想到利用eclipse的search功能配合正则表达式. 在eclipse中Ctrl+H,然后在Containing text中输入[\u4e00-\u ...

  5. mysql语法、特殊符号及正則表達式的使用

    http://blog.csdn.net/pipisorry/article/details/46773545 sql语言 结构化的查询语言.(Structured Query Language),是 ...

  6. 翻译:A Tutorial on the Device Tree (Zynq) -- Part I

    A Tutorial on the Device Tree (Zynq) -- Part I 此教程的目的 本教程是针对Xilinx' Zynq-7000 EPP设备(一个集成了FPGA的ARM Co ...

  7. JavaScript中label语句的使用

    之前在读<javascript高级程序设计>的时候,看到过lable语句,当时看完感觉好像很少用到,但是今天,刚好在项目终于到了合适的场景,合理使用label可以大幅度优化性能. 首先来简 ...

  8. Do not use the <section> element as a generic container; this is what <div> is for, especially when the sectioning is only for styling purposes.

    Do not use the <section> element as a generic container; this is what <div> is for, espe ...

  9. inheritance super overrides printMethod in Superclass override重写父方法

    Core Java Web Page http://horstmann.com/corejava.html [ inheritance ] package v1ch05.inheritance; im ...

  10. 20170224 SE11删除数据

    目的,批量删除错误条目.1.SE11 通过条件找到目标数据,并选中: 2./H 进入debug,回车,更改值 OK_CODE  =  DEL5 F8 运行则出现删除框,