[COGS383]单向双轨道解题报告
2014-12-01 20:55
267 查看
①做这道题的时候没有认真思考,以为跟双栈排序一样然后就蛋疼了,蛋疼了好久才发现原来不一样!由于可以从栈A到栈B,所以在栈A中的元素是不一定有序的,而栈B中的元素才是一定有序的;我一开始误以为了二者均是有序的。
②这道题显然应该是DFS-ID,我却一上来就写了个BFS,导致爆掉了。
③DFS-ID的上限3*N才是比较合适的,因为其实这个题26好像是搜不了的。。所以用26*3的话。。呵呵。
②这道题显然应该是DFS-ID,我却一上来就写了个BFS,导致爆掉了。
③DFS-ID的上限3*N才是比较合适的,因为其实这个题26好像是搜不了的。。所以用26*3的话。。呵呵。
#include<iostream> using namespace std; #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<cmath> char s[6][10]={" A B\n"," A C\n"," A D\n"," B C\n"," B D\n"," C D\n"}; int tmp[4][30],change[200000],m,order[30],n; bool flag; struct S{ int s,t; }b[10]={(S){0,1},(S){0,2},(S){0,3},(S){1,2},(S){1,3},(S){2,3}}; inline void prt(int x){ int a=tmp[b[change[x]].s][++tmp[b[change[x]].s][0]]=tmp[b[change[x]].t][tmp[b[change[x]].t][0]--]; if(x)prt(x-1); printf("%c%s",(char)(a+'a'),s[change[x]]); } inline void dfs(int x){ if(n-tmp[3][0]>m-x)return; if(tmp[3][0]==n){ prt(x-1); exit(0); } if(x==m)return; for(int i=0;i<6;++i){ if((n&1)&&i==0&&tmp[1][0]&&(!tmp[2][0]||(tmp[1][0]==2&&tmp[2][0]==2)))continue; if(tmp[b[i].s][0]){ if(b[i].t==3&&(tmp[3][0]?order[tmp[3][tmp[3][0]]]+1!=order[tmp[b[i].s][tmp[b[i].s][0]]]:order[tmp[b[i].s][tmp[b[i].s][0]]]!=1))continue; tmp[b[i].t][++tmp[b[i].t][0]]=tmp[b[i].s][tmp[b[i].s][0]--]; change[x]=i; dfs(x+1); tmp[b[i].s][++tmp[b[i].s][0]]=tmp[b[i].t][tmp[b[i].t][0]--]; } } } int main(){ freopen("track.in","r",stdin); freopen("track.out","w",stdout); int i; char s[30]; scanf("%d%s",&n,s); for(i=0;i<n;++i)order[s[i]-'a']=n-i; tmp[0][0]=n; for(i=0;i<n;++i)tmp[0][i+1]=i; while(m<3*n){ ++m; dfs(0); } printf("NO"); }
相关文章推荐
- 【解题报告】uva116_Unidirectional TSP(单向TSP, dp)
- [bzoj2861] 双向边定向为单向边 解题报告
- POJ_2828解题报告
- 全国信息学分区联赛模拟试题(三)_____解题报告
- 解题报告 征兵计划
- 杭电ACM hdu 1085 Holding Bin-Laden Captive! 解题报告(母函数)
- HDU 2602 Bone Collector 解题报告(dp入门题)
- 解题报告 poj 2109
- poj1003"Hangover"解题报告
- 解题报告 ch1 排序与搜素
- noip2009普及组道路游戏解题报告
- 解题报告 Valentine‘s present
- [LeetCode]Binary Tree Level Order Traversal II,解题报告
- 九度OJ题目1013:开门人和关门人解题报告
- 2014 NOIP复赛提高组 C++ 解题报告
- hdu 2844 Coins 解题报告
- codeforces #133 div2 解题报告
- leetcode解题报告15. 3Sum
- LuoguP1941[NOIP2014] 飞扬的小鸟 解题报告【背包型DP】
- 八数码解题报告