https://acm.ecnu.edu.cn/contest/125/problem/C/
题解:卡着时间过的23333
首先XY的排列记录
再排列组合数
最后Q操作
用一个vector存储X的下标可以节约时间,不是一点点
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
using namespace std;
typedef long long ll;
const int N=10000;
const ll M=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,q,k;
char str[2000+100];
int a[2000+100][110];
ll c[2000+100][2000+100];
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
scanf("%s",str);
int len=strlen(str);
vector<short>v[10];
c[0][0]=1;
for(int i=0;i<len;i++){
int a1=(str[i]-'0')*10-'0';
v[str[i]-'0'].push_back(i);
k=i+1;
for(int j=k;j<len;j++){
a[i][a1+str[j]]++;
}
c[k][0]=1;c[k][k]=1;
for(int j=1;j<k;j++){
c[k][j]=(c[i][j-1]+c[i][j])%M;
}
}
scanf("%d",&q);
while(q--){
scanf("%d%d",&m,&t);
if(m==1||m>len){
cout << 0 << endl;
continue;
}
ll ans=0;
int m1=m-2;
int t1=t/10;
int s=v[t1].size();
for(int i=0;i<s;i++){
int d=v[t1][i];
if(d<m1)
continue;
if(a[d][t]){
ans=ans+a[d][t]*c[d][m1];
}
}
cout << ans%M << endl;
}
//cout << "Hello world!" << endl;
return 0;
}