Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int maxn = 2005;
- const int max_weight = 3550;
- const int INF = 1e9;
- string s;
- int dp[maxn];
- int rec(int at) {
- if(at >= s.size()) {
- return 1;
- }
- if(dp[at] != -1) {
- return dp[at];
- }
- int result = 0;
- if(s[at] != '0') {
- result += rec(at + 1);
- }
- if(at + 1 < s.size() and s[at] != '0') {
- int tmp_number = (s[at] - '0') * 10 + (s[at + 1] - '0');
- if(tmp_number <= 26 and tmp_number != 0) {
- result += rec(at + 2);
- }
- }
- return dp[at] = result;
- }
- int main() {
- cin >> s;
- for(int i = 0; i < maxn; i++) {
- dp[i] = -1;
- }
- cout << rec(0) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement