http://www.lightoj.com/volume_showproblem.php?problem=1125
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 #define N 205 6 #define LL long long 7 LL dp[N][11][21][21]; 8 LL num[N]; 9 void init(int n) 10 { 11 memset(dp,0,sizeof(dp)); 12 for(int k=1;k<=20;k++){ 13 LL c=2100000000; 14 LL tmp=(num[1]+k*c)%k; 15 dp[1][1][k][tmp]++; 16 } 17 18 for(LL i=2;i<=n;i++) 19 for(LL j=1;j<=min(i,(LL)10);j++) 20 for(LL k=1;k<21;k++) 21 for(LL l=0;l<k;l++){ 22 LL c=2100000000; 23 LL tmp=(num[i]+k*c)%k; 24 if(j==1){ 25 dp[i][j][k][l]=dp[i-1][j][k][l]; 26 if(tmp==l) 27 dp[i][j][k][l]++; 28 } 29 else 30 dp[i][j][k][l]=dp[i-1][j][k][l]+dp[i-1][j-1][k][(k+l-tmp)%k]; 31 } 32 } 33 int main() 34 { 35 int t,cas=1; 36 scanf("%d",&t); 37 while(t--){ 38 int n,q; 39 scanf("%d%d",&n,&q); 40 for(int i=1;i<=n;i++) 41 scanf("%lld",num+i); 42 init(n); 43 //print(n); 44 printf("Case %d:\n",cas++); 45 while(q--){ 46 int a,b; 47 scanf("%d%d",&a,&b); 48 printf("%lld\n",dp[n][b][a][0]); 49 } 50 } 51 return 0; 52 }