ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#205296 | #3663. 拆分数计数 | snow_trace | 100 | 13ms | 1280kb | C++11 | 1.0kb | 2024-07-01 08:28:44 | 2024-07-01 13:02:25 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1000000007;
int a[10005];
char s[100005];
const int M = 3500;
int dp[4005][2];
signed main(){
scanf("%s",s+1);int len = strlen(s+1),head = 1,l = len;
for(int i =0;i<M;i++){
if(head == l+1){a[i] = 0;continue;}
if((s[l]-'0')%2 == 1){
s[l]--,a[i] = 1;
}else a[i] = 0;
for(int i = l;i>=head;i--){
if((s[i]-'0')&1)s[i+1]+=5;
s[i] = '0'+(s[i]-'0')/2;
}
// for(int i = head;i<=l;i++)cout << s[i] << " ";cout <<endl;
if(s[head]== '0')++head;
}
// for(int i = 0;i<20;i++)cout << a[i];cout << endl;
if(a[0] == 1)dp[0][0] = 1;
else dp[0][0] = dp[0][1] = 1;
for(int i= 1;i<=M;i++){
if(a[i] == 0){
dp[i][1] = (dp[i][1]+dp[i-1][0]+dp[i-1][1])%mod;
dp[i][0] = (dp[i][0]+dp[i-1][0])%mod;
}else{
dp[i][1] = (dp[i][1]+dp[i-1][1])%mod;
dp[i][0] = (dp[i][0]+dp[i-1][0]+dp[i-1][1])%mod;
}
}
cout << dp[M][0] << endl;
return 0;
}
/*
从小到大放有很好的性质。
瓶颈是高精度二进制分解。
*/
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1276kb
input:
16
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 10
Accepted
time: 0ms
memory: 1280kb
input:
49
output:
7
result:
ok 1 number(s): "7"
Test #3:
score: 10
Accepted
time: 0ms
memory: 1276kb
input:
36185
output:
574
result:
ok 1 number(s): "574"
Test #4:
score: 10
Accepted
time: 0ms
memory: 1280kb
input:
12469
output:
193
result:
ok 1 number(s): "193"
Test #5:
score: 10
Accepted
time: 0ms
memory: 1276kb
input:
268435456
output:
29
result:
ok 1 number(s): "29"
Test #6:
score: 10
Accepted
time: 0ms
memory: 1276kb
input:
886963342
output:
79283
result:
ok 1 number(s): "79283"
Test #7:
score: 10
Accepted
time: 0ms
memory: 1276kb
input:
857111419310807500
output:
587805658
result:
ok 1 number(s): "587805658"
Test #8:
score: 10
Accepted
time: 0ms
memory: 1280kb
input:
241759640534962508
output:
767627753
result:
ok 1 number(s): "767627753"
Test #9:
score: 10
Accepted
time: 5ms
memory: 1280kb
input:
2008999756307389289461098358035312645634707221534336714125655485376852595618160065610595506295869701...
output:
2334
result:
ok 1 number(s): "2334"
Test #10:
score: 10
Accepted
time: 8ms
memory: 1276kb
input:
9325631759829183009185228263798670160985186098483993056211580931423159672143986338581788893197442167...
output:
152579827
result:
ok 1 number(s): "152579827"
Extra Test:
score: 0
Extra Test Passed