hihocoder 1033 인터레이싱 및 디지털 DP
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define N 1000000007
#define LL long long
struct node
{
    LL cnt;
    LL sum;
}dp[20][202][2];
int num[20];
LL c[20],k;
node dfs(int site,int sum,int f,int p,int flag)
{
    if(site==0)
    {
        node a;
        if(flag) a.cnt=0;
        else
        a.cnt=sum==100?1:0;
        a.sum=0;
        return a;
    }
    if(!f&&!flag&&dp[site][sum][p].cnt!=-1)
        return dp[site][sum][p];
    node ans,a;
    ans.cnt=ans.sum=0;
    int len=f?num[site]:9;
    for(int i=0;i<=len;i++)
    {
        if(flag&&i==0)
        {
            a=dfs(site-1,sum,f&&i==len,p,flag);
        }
        else
        {
        if(p)
            a=dfs(site-1,sum-i,f&&i==len,p^1,0);
        else
            a=dfs(site-1,sum+i,f&&i==len,p^1,0);
        }
        ans.cnt=(ans.cnt+a.cnt)%N;
        ans.sum=(ans.sum+((c[site]*a.cnt)%N)*i+a.sum)%N;
    }
    if(!f&&!flag)
    {
        dp[site][sum][p].cnt=ans.cnt;
        dp[site][sum][p].sum=ans.sum;
    }
    return ans;
}
LL solve(LL n)
{
    int i=0;
    while(n)
    {
        num[++i]=n%10;
        n=n/10;
    }
    node ans;
    ans=dfs(i,k+100,1,1,1);
    return ans.sum;
}
int main()
{
    LL l,r;
    memset(dp,-1,sizeof(dp));
    c[1]=1;
    for(int i=2;i<=18;i++)
        c[i]=(c[i-1]*10)%N;
    while(scanf("%lld %lld %d",&l,&r,&k)!=EOF)
    {
        printf("%lld
",((solve(r)-solve(l-1))%N+N)%N);
    }
    return 0;
}
       
                이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
01 가방, 완전 가방, 다중 가방 dp(동적 기획 입문 dp)01 가방은 2진법으로 직접 표시할 수 있지만 데이터 양이 너무 많으면 시간을 초과하는 것이 폭력이다.01 가방의 사상은 바로 이 물품에 대해 내가 넣은 가치가 큰지 안 넣은 가치가 큰지 비교하여 방정식 f[i][v...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.