Untitled
raw download clone
TEXT
views 34
,
size 1064 b
#include<stdio.h>
#include<string.h>
#define MOD 1000000007
char s[2000005];
char temp[2000005];
long long int s_len, l,add;
void sub(int a,int b);

int main ()
{
    int t, x;
    scanf("%d",&t);
    for(int i=0;i<t;i++)
    {

        scanf("%d",&x);
        scanf("%s",s);
        s_len=strlen(s);
        l=strlen(s);
        for(int i=1; i<=x; i++)
        {
            int left=s[i-1]-'0';
            add=(((l-i)%MOD)*(left-1))%MOD; //新增的長度
            l=(l+add)%MOD; //總長度
            if(s_len<=x&&left>1)
            {
                sub(i,s_len-1);
                long long int t_len=strlen(temp);
                for(int j=1; j<=left-1&&s_len<=x; j++)
                {
                    strcat(s,temp);
                    s_len+=t_len;
                }
            }
        }
        if(l<0)
            l+=MOD;
        printf("%lld\n",l);
    }
}
void sub(int f,int end)
{
    memset(temp, '\0', strlen(temp));
    for(int i=f; i<=end; i++)
    {
        temp[i-f]=s[i];
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.