还没写完的时间复杂度

 1 # include <cstdio>
 2 # include <iostream>
 3 # include <cstring>
 4 # include <cstring>
 5 
 6 using namespace std;
 7 
 8 int t,len,nl,Std,dep;
 9 string st,pr[105];
10 bool uke,f,vis[30]={0};
11 int sta[108];
12 int ans[108];
13 
14 void ac()
15 {
16     for (int i=1;i<=len;i++)
17     {
18         if(pr[i][0]=='F')
19         {
20             dep++;
21             sta[dep]=pr[i][2]-'a';
22             if (vis[sta[dep]]) uke=true;
23             vis[sta[dep]]=true;
24         }
25         else
26         {
27             if(dep==0) uke=true;
28             vis[sta[dep]]=false;
29             dep--;
30         }
31     }
32     if(dep!=0) uke=true;
33     return ;
34 }
35 
36 void wa()
37 {
38     for (int i=1;i<=len;i++)
39     {
40         if(pr[i][0]=='F')
41         {
42             dep++;
43             F[dep]=  //本层的复杂度,如果不进入循环即为0
44              
45         }
46         else
47         {
48             dep--;
49             ans[dep]=max(ans[dep],max(ans[dep+1],1)*F[dep]);  //如果dep+1这一层这一个循环的复杂度是dep层中嵌套的最大的一层 ,就认为dep层的复杂度是这样 
50         }
51     }
52     if(ans[0])
53     return ;
54 }
55 
56 int main()
57 {
58     scanf("%d",&t);
59     for (int shzr=1;shzr<=t;shzr++)
60     {
61         scanf("%d",&len);
62         getline(cin,st);
63         if(st[2]=='1') Std=0;
64         else
65         {
66             if(st[5]==')') Std=st[4]-'0';
67             else          Std=(st[4]-'0')*10+st[5]-'0';
68         }
69         memset(vis,0,sizeof(vis));
70         uke=f=false;
71         for (int i=1;i<=len;i++)
72             getline(cin,pr[i]);
73         dep=0;
74         ac();
75         if(uke) printf("ERR\n");
76         else
77         {
78             dep=0;
79             wa();
80             if(f) printf("Yes\n");
81             else       printf("No\n");
82         }
83     }
84     return 0;
85 }

猜你喜欢

转载自www.cnblogs.com/shzr/p/9056388.html