File tree 1 file changed +57
-0
lines changed
1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ /* Amit Bansal - @amitbansal7 */
2
+ #include < bits/stdc++.h>
3
+ #include < string>
4
+ #define lli long long int
5
+ #define llu unsigned long long int
6
+ #define S (x ) scanf(" %d" ,&x)
7
+ #define Sl (x ) scanf(" %lld" ,&x)
8
+ #define Mset (p,i ) memset(p,i,sizeof (p))
9
+ #define mlc (t,n ) (t *)malloc(sizeof (t)*n)
10
+ #define NIL -1
11
+ #define INF INT_MAX
12
+ #define TC int testcase; S(testcase); while (testcase--)
13
+ #define Pi 3.14159
14
+ using namespace std ;
15
+
16
+ bool valid (char c){ return c!=' 0' ; }
17
+ bool valid (char a,char b){ return a==' 1' || (a==' 2' && b<=' 6' ); }
18
+
19
+ llu solve (string s,int i,llu DP[])
20
+ {
21
+ if (i<=1 )
22
+ return 1 ;
23
+
24
+ if (DP[i] != -1 )
25
+ return DP[i];
26
+
27
+ llu a = 0 ;
28
+ char b = s[i-1 ];
29
+ char c = s[i-2 ];
30
+ if (valid (b))
31
+ a = solve (s,i-1 ,DP);
32
+
33
+ if (valid (c,b))
34
+ a += solve (s,i-2 ,DP);
35
+
36
+ return DP[i] = a;
37
+ }
38
+
39
+ int main (int argc, char const *argv[])
40
+ {
41
+ string s;
42
+ while (1 )
43
+ {
44
+ cin>>s;
45
+ if (s[0 ] == ' 0' )
46
+ break ;
47
+
48
+ llu DP[s.size ()+1 ];
49
+ for (int i=0 ;i<=s.size ();i++)
50
+ DP[i] = -1 ;
51
+
52
+ llu ans = solve (s,s.size (),DP);
53
+ cout<<ans<<endl;
54
+ }
55
+
56
+ return 0 ;
57
+ }
You can’t perform that action at this time.
0 commit comments