fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #define ll long long
  5. using namespace std;
  6. const int maxn = 100000;
  7. ll c[5],q,d[5],v,dp[maxn+1];
  8. void solve()
  9. {
  10. for (int i=1; i<=4; i++)
  11. cin >> c[i];
  12. cin >> q;
  13. memset(dp,0,sizeof(dp));
  14. dp[0]=1;
  15. for (int i=1; i<=4; i++)
  16. for (int j=c[i]; j<=maxn; j++)
  17. {
  18. //cout << i*j << '\n';
  19. dp[j]+=dp[j-c[i]];
  20. }
  21. //cout << dp[c[1]*2] << '\n';
  22. //cout << "Done\n";
  23. for (int i=1; i<=q; i++)
  24. {
  25. for (int j=1; j<=4; j++)
  26. cin >> d[j];
  27. cin >> v;
  28. ll res=0;
  29. for (int j=0; j<16; j++)
  30. {
  31. int dem=0;
  32. int dv=v;
  33. int jj=j;
  34. int vt=0;
  35. while (jj!=0)
  36. {
  37. vt++;
  38. dem+=jj%2;
  39. if (jj%2==1)
  40. {
  41. dv-=(d[vt]+1)*c[vt];
  42. //cout << vt << ' ';
  43. }
  44. jj/=2;
  45. }
  46. //cout << dv << ' ';
  47. if (dv>=0)
  48. {
  49. if (dem%2==0) res+=dp[dv];
  50. else res-=dp[dv];
  51. }
  52. }
  53. cout << res << '\n';
  54. }
  55. }
  56. int main()
  57. {
  58. ios_base::sync_with_stdio(0);
  59. //freopen("11259.INP","r",stdin);
  60. int t;
  61. cin >> t;
  62. for (int i=1; i<=t; i++)
  63. {
  64. //cout << i << '\n';
  65. solve();
  66. }
  67. return 0;
  68. }
Success #stdin #stdout 0s 4188KB
stdin
Standard input is empty
stdout
Standard output is empty