社区讨论
poj过了,洛谷没过,为什么QwQ
UVA124Following Orders参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mi7cjih8
- 此快照首次捕获于
- 2025/11/20 19:27 4 个月前
- 此快照最后确认于
- 2025/11/20 19:27 4 个月前
poj过了但是这里过不了哎...
代码
CPP//POJ 1270 Following Orders
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int ans[30],vis[30],c,n,m[30],g[30][30],a,b;
string str;
bool check(int i,int c)
{
for(int j=0;j<c;j++) if(g[i][ans[j]]) return false;
return true;
}
void dfs(int c)
{
if(c==n)
{
for(int i=0;i<n;i++) printf("%c",ans[i]+'a');
printf("\n");
}
else
{
for(int i=0;i<26;i++)
{
if(m[i]&&!vis[i]&&check(i,c))
{
vis[i]=1;
ans[c]=i;
dfs(c+1);
vis[i]=0;
}
}
}
}
int main()
{
while(getline(cin,str))
{
n=0;
memset(m,0,sizeof(m));
memset(g,0,sizeof(g));
memset(vis,0,sizeof(vis));
for(int i=0;str[i];i++)
{
if(str[i]!=' ')
{
m[str[i]-'a']=1;
n++;
}
}
getline(cin,str);
for(int i=0;str[i];i++)
{
if(str[i]!=' ')
{
a=str[i++]-'a';
while(str[i]==' ') i++;
b=str[i]-'a';
g[a][b]=1;
}
}
dfs(0);
puts("");
}
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...