forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquishedStatus.cpp
More file actions
57 lines (50 loc) · 1015 Bytes
/
Copy pathSquishedStatus.cpp
File metadata and controls
57 lines (50 loc) · 1015 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
56
57
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <string>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
typedef long long LL;
#define MOD 4207849484LL
int M, len;
string status;
LL mm[1005];
LL dp(int idx) {
LL& ret = mm[idx];
if (ret != -1) return ret;
if (idx >= len) return ret = 1;
ret = 0;
LL tmp = 0;
FOR(i,idx,len-1) {
tmp = tmp * 10 + status[i] - '0';
if (tmp < 1 || tmp > M) break;
ret = (ret + dp(i + 1)) % MOD;
}
return ret;
}
void run() {
cin >> M >> status;
len = status.length();
REP(i,1005) mm[i] = -1;
LL ret = dp(0);
cout << ret << endl;
}
int main() {
int kase;
cin >> kase;
FOR(k,1,kase) {
cout << "Case #" << k << ": ";
run();
}
return 0;
}