-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathacode.cpp
More file actions
55 lines (46 loc) · 993 Bytes
/
acode.cpp
File metadata and controls
55 lines (46 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define inf 1000000000
#define MAXN 5005
using namespace std;
string code;
int dp[MAXN];
int limit;
int rek(int idx = 0) {
if (idx > limit) return 1;
if (dp[idx]) return dp[idx];
if (code[idx] == '0') return 0;
if (idx+1 < limit
&& (code[idx] == '1' || (code[idx] == '2' && code[idx+1] <= '6'))) {
if (code[idx+1] == '0')
return dp[idx] = rek(idx+2);
else
return dp[idx] = rek(idx+1) + rek(idx+2);
}
else return dp[idx] = rek(idx+1);
}
int main() {
cin.sync_with_stdio(false);
while (true) {
getline(cin, code);
if (code[0] == '0') break;
limit = code.size();
memset(dp, 0, sizeof dp);
printf("%d\n", rek());
}
return 0;
}