fork download
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3. using namespace std;
  4. using ll = long long;
  5.  
  6. ll dp[3010][3010];
  7. int n,m;
  8. ll pre[3010];
  9. ll a[3010];
  10. ll b[3010];
  11. ll MOD = 1000000007;
  12.  
  13. int main(){
  14. ios_base::sync_with_stdio(false);
  15. cin.tie(NULL);
  16. freopen("DIVGROUP.INP","r",stdin);
  17. freopen("DIVGROUP.OUT","w",stdout);
  18. cin >> n >> m;
  19. for(int i = 1; i <= n; i++){
  20. cin >> a[i];
  21. pre[i] += pre[i-1] + a[i];
  22. }
  23. for(int j = 1; j <= m; j++){
  24. cin >> b[j];
  25. }
  26. dp[0][0] = 1;
  27. for(int j = 1; j <= m; j++){
  28. for(int i = j; i <= n; i++){
  29. for(int k = j - 1; k < i; k++){
  30. if((pre[i] - pre[k]) % b[j] == 0){
  31. dp[i][j] = (dp[i][j] + dp[k][j-1]) % MOD;
  32. }
  33. }
  34. }
  35. }
  36. cout << dp[n][m];
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty