首页 > 其他分享 >Divide by Zero 2021 and Codeforces Round #714 C

Divide by Zero 2021 and Codeforces Round #714 C

时间:2022-10-18 23:12:51浏览次数:62  
标签:10 const Divide int 714 Codeforces ans dp

C. Add One

显然对于每一位单独分析
我们经过一次进位只能变成10
这样该怎么做呢
我们显然可以dp
设dp[i][j]表示i(0-9)经过j次变换有几位
显然我们初始化i+j<10就是1
else dp[i][j]=dp[1][i+j-10]+dp[0][i+j-10]
就是我们变成10需要十次我们减去这十次即可

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
const int M = 998244353;
const int mod = 1e9+7;
#define int long long
int up(int a,int b){return a<0?a/b:(a+b-1)/b;}
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define pi acos(-1)
#define INF 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);
int dp[10][N];
void solve() {
    string s;cin>>s;
    int n;cin>>n;
    int ans=0;
    for(auto i:s){
        (ans+=dp[i-'0'][n])%=mod;
    }
    cout<<ans<<endl;
}
signed main(){
    fast
    int t;t=1;cin>>t;
    for(int j=0;j<=2e5;j++)
        for(int i=0;i<10;i++)
            if(i+j<10)dp[i][j]=1;
            else dp[i][j]=(dp[1][j+i-10]+dp[0][j+i-10])%mod;
    while(t--) {
        solve();
    }
    return ~~(0^_^0);
}

标签:10,const,Divide,int,714,Codeforces,ans,dp
From: https://www.cnblogs.com/ycllz/p/16804562.html

相关文章