forked from t3nsor/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathanarc05h.cpp
More file actions
29 lines (29 loc) · 706 Bytes
/
Copy pathanarc05h.cpp
File metadata and controls
29 lines (29 loc) · 706 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
// 2014-05-28
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
long long memo[26][230];
long long rec(const string& s, int pos, int last) {
if (pos == s.length()) return 1;
long long& res = memo[pos][last];
if (res == -1) {
res = 0;
int sum = 0;
for (int i = pos; i < s.length(); i++) {
sum += s[i] - '0';
if (sum >= last) {
res += rec(s, i+1, sum);
}
}
}
return res;
}
int main() {
for (int _cs = 1;; _cs++) {
string s; cin >> s;
if (s == "bye") return 0;
memset(memo, -1, sizeof memo);
printf("%d. %lld\n", _cs, rec(s, 0, 0));
}
}