UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205309#3663. 拆分数计数cjwen1006ms1228kbC++111.8kb2024-07-01 11:47:122024-07-01 13:04:14

answer

#include<bits/stdc++.h>

using namespace std;

const int N = 4010, P = 1e9+7;

struct modint{
    int _v = 0;

    modint(long long x = 0){
        _v = x % P;
        if(_v < 0) _v += P;
    }

    modint operator+ (const modint &oy) const{
        return modint(_v + oy._v);
    }
    modint operator- (const modint &oy) const{
        return modint(_v - oy._v);
    }
    modint operator* (const modint &oy) const{
        return modint((long long)_v * oy._v);
    }

    modint &operator+= (const modint &oy){
        _v += oy._v;
        if(_v >= P) _v -= P;
        return *this;
    }
    modint &operator-= (const modint &oy){
        _v -= oy._v;
        if(_v < 0) _v += P;
        return *this;
    }
    modint &operator*= (const modint &oy){
        _v = ((long long)_v * oy._v) % P;
        return *this;
    }

    operator int() const{
        return _v;
    }
};

int n;
char a[N];
int b[N];
int c[N], m;

void chu(){
    int t = 0;
    for(int i = n; i; i--){
        b[i] += t*10;
        t = b[i]%2;
        b[i] /= 2;
    }
    while(n && b[n] == 0){
        n--;
    }
}

modint f[N][2];

int main(){

    scanf("%s", a+1);
    n = strlen(a+1);
    for(int i = 1; i <= n; i++){
        b[i] = a[n+1-i]-'0';
    }

    while(n){
        c[++m] = b[1]%2;
        chu();
    }

    // for(int i = m; i; i--){
    //     printf("%d", c[i]);
    // }
    // puts("");

    f[m+1][0] = 1;
    for(int i = m; i; i--){
        if(c[i] == 1){
            f[i][0] += f[i+1][0];
            f[i][1] += f[i+1][0];
            f[i][1] += f[i+1][1];
        }else{
            f[i][0] += f[i+1][0];
            f[i][0] += f[i+1][1];
            f[i][1] += f[i+1][1];
        }
    }

    printf("%d\n", f[1][0]);

    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1212kb

input:

16

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 10
Accepted
time: 0ms
memory: 1212kb

input:

49

output:

7

result:

ok 1 number(s): "7"

Test #3:

score: 10
Accepted
time: 0ms
memory: 1216kb

input:

36185

output:

574

result:

ok 1 number(s): "574"

Test #4:

score: 10
Accepted
time: 0ms
memory: 1216kb

input:

12469

output:

193

result:

ok 1 number(s): "193"

Test #5:

score: 10
Accepted
time: 0ms
memory: 1212kb

input:

268435456

output:

29

result:

ok 1 number(s): "29"

Test #6:

score: 10
Accepted
time: 1ms
memory: 1212kb

input:

886963342

output:

79283

result:

ok 1 number(s): "79283"

Test #7:

score: 10
Accepted
time: 1ms
memory: 1216kb

input:

857111419310807500

output:

587805658

result:

ok 1 number(s): "587805658"

Test #8:

score: 10
Accepted
time: 0ms
memory: 1216kb

input:

241759640534962508

output:

767627753

result:

ok 1 number(s): "767627753"

Test #9:

score: 10
Accepted
time: 0ms
memory: 1228kb

input:

2008999756307389289461098358035312645634707221534336714125655485376852595618160065610595506295869701...

output:

2334

result:

ok 1 number(s): "2334"

Test #10:

score: 10
Accepted
time: 4ms
memory: 1228kb

input:

9325631759829183009185228263798670160985186098483993056211580931423159672143986338581788893197442167...

output:

152579827

result:

ok 1 number(s): "152579827"

Extra Test:

score: 0
Extra Test Passed