Description
Input
Output
Sample Input
2
1 1 5 100
3
2 0 7 7
2 2
Sample Output
16
0
Data Constraint
solution
日常先打指数暴力dfs水30分
1 void dfs(int x, int y) 2 { 3 if(x == n + 1 && y == 1) 4 { 5 int sum = 0; 6 for(R int i = 1; i <= n; i++) 7 { 8 int kkk = 1; 9 for(R int j = 1; j <= a[i]; j++) 10 { 11 kkk *= b[i][j]; 12 } 13 sum = (sum + kkk) % p; 14 } 15 if(sum == c) ans++, ans %= m ; 16 return; 17 } 18 if(y == a[x]) 19 { 20 for(R int i = 0; i < p; i++) 21 { 22 b[x][y] = i; 23 dfs(x + 1, 1); 24 b[x][y] = 0; 25 } 26 return; 27 } 28 for(R int i = 0; i < p; i++) 29 { 30 b[x][y] = i; 31 dfs(x, y + 1); 32 b[x][y] = 0; 33 } 34 return; 35 } 36 signed main() 37 { 38 freopen("congruence.in","r",stdin); 39 freopen("congruence.out","w",stdout); 40 read(t); 41 while(t--) 42 { 43 read(n); read(c); read(p); read(m ); 44 ans = 0; 45 for(R int i = 1; i <= n; i++) read(a[i]); 46 dfs(1, 1); 47 writeln(ans); 48 } 49 return 0; 50 }
先挖坑,A了再来