-
Notifications
You must be signed in to change notification settings - Fork 1
/
1416.恢复数组.cpp
58 lines (52 loc) · 1.26 KB
/
1416.恢复数组.cpp
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
58
#include "s.h"
/*
* @lc app=leetcode.cn id=1416 lang=cpp
*
* [1416] 恢复数组
*/
// @lc code=start
class Solution {
public:
int numberOfArrays(string s, int k) {
int n = s.size();
vector<long long> dp(n+1,1);
// int kn = 0,tmpk=k;
// while(tmpk){
// tmpk/=10;
// kn++;
// }
long long mo = 1000000007;
for(int i=0;i<n;i++){
long long cur = s[i]-'0';
int j = i;
long long tmp=0;
while(cur<=k){
if(cur>=1){
tmp = (tmp+dp[j])%mo;
}
long long carry= 10;
while (cur/carry>0)
{
carry*=10;
}
j--;
while(j>=0 && s[j]=='0' && carry<mo){
carry*=10;
j--;
}
if(j>=0 && carry<mo){
cur = carry*(s[j]-'0')+cur;
}else{
break;
}
}
dp[i+1] = tmp;
}
return dp[n];
}
};
// @lc code=end
int main(){
Solution s;
cout << s.numberOfArrays("1317", 2000);
}