Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
能帮忙看一下哪里错吗?谢谢!!感觉自己思路对了,但它说错误答案,但提供的数据都测试对啊#include <iostream> #include <cstring> using namespace std; char pre[27]; char pos[27]; int m=0; int ary=0; int brother[27]; int record[27]; int level=0; int result=0; int comp(int i) { int s=-1,t=-1; for (int c=0;c<strlen(pre);c++) { if (pos[c]==pre[i]) { s=c; } if (pos[c]==pre[i+1]) { t=c; } if (t!=-1&&s!=-1) { break; } } if (s-t<0) { return 0; } else return 1; } void dfs(int i) { if (i==strlen(pre)-1) { for (int oo=1;oo<=level;oo++) { int tmp=1; for (int j=1;j<=brother[oo];j++) { tmp=tmp*(ary-j+1)/j; } result=result*tmp; } return; } int ret=comp(i); if (ret==1) { brother[++level]++; record[i+1]=level; dfs(i+1); } else { int tt; int kk; int ss=0; int ll; for (ll=0;ll<strlen(pre);ll++) { if (pos[ll]==pre[i+1]) { break; } } for (tt=ll+1;pos[tt]!='\0';tt++) { for (kk=i;kk>=0;kk--) { if (pre[kk]==pos[tt]) { ss=1; break; } } if (ss==1) { break; } } int qq=record[kk]+1; brother[qq]++; record[i+1]=qq; dfs(i+1); } } int main() { while (1) { memset(pre,0,sizeof(pre)); memset(pos,0,sizeof(pos)); memset(brother,0,sizeof(brother)); memset(record,0,sizeof(0)); m=0; level=0; result=1; cin >> ary; if (ary==0) { break; } cin >> pre >> pos; if (strlen(pre)==1) { result=1; } else dfs(0); cout << result << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator