首页 > 代码库 > BZOJ 4421 Digit Division

BZOJ 4421 Digit Division

随便dp一下就好了。。。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#define maxn 300050#define maxm 1000050#define mod 1000000007using namespace std;long long n,m,t[maxn],sum[maxm],dp[maxn];char s[maxn];int main(){    scanf("%lld%lld",&n,&m);    scanf("%s",s);    dp[0]=sum[0]=1;    for (long long i=1;i<=n;i++)        t[i]=(t[i-1]*10+s[i-1]-0)%m;    for (long long i=1;i<=n;i++)    {        dp[i]=sum[t[i]];        sum[t[i]]=(sum[t[i]]*2)%mod;    }    printf("%lld\n",dp[n]%mod);    return 0;} 

 

BZOJ 4421 Digit Division