fork(2) download
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4. const int N = 100000, M = 1000000007;
  5. int n, t, a[N], dp[N];
  6.  
  7. int calc(int i) {
  8. if (i == n) return 1;
  9. int &ret = dp[i];
  10. if (ret != -1) return ret;
  11. ret = calc(i + 1);
  12. ret = (ret + (ll)a[i] * calc(i + 1)) % M;
  13. return ret;
  14. }
  15.  
  16. int main() {
  17. scanf("%d", &t);
  18. while (t--) {
  19. scanf("%d", &n);
  20. for (int i = 0; i < n; i++)
  21. scanf("%d", &a[i]);
  22. memset(dp, -1, sizeof dp);
  23. printf("%d\n", calc(0) - 1);
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 16016KB
stdin
Standard input is empty
stdout
Standard output is empty