Advertisement
Saleh127

Light oj(LO) 1231

May 18th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10.  
  11. test
  12. {
  13.  
  14. ll n,m,i,j,k,h,l=100000007;
  15.  
  16. cin>>n>>k;
  17.  
  18. ll a[n+2],c[n+2];
  19.  
  20.  
  21. ll dp[k+5];
  22.  
  23. for(i=0;i<=k+2;i++)
  24. {
  25. dp[i]=0;
  26. }
  27.  
  28. dp[0]=1;
  29.  
  30.  
  31.  
  32. for(i=0; i<n; i++)
  33. {
  34. cin>>a[i];
  35. }
  36.  
  37. for(i=0; i<n; i++)
  38. {
  39. cin>>c[i];
  40. }
  41.  
  42. for(i=0; i<n; i++)
  43. {
  44. for(h=k; h>0; h--)
  45. {
  46. for(j=1; j<=c[i]; j++)
  47. {
  48. if(h>=(j*a[i]))
  49. {
  50. dp[h]=(dp[h]+dp[h-(j*a[i])])%l;
  51. }
  52. }
  53. }
  54.  
  55. }
  56.  
  57. cout<<"Case "<<cs<<": "<<dp[k]<<endl;
  58.  
  59. }
  60.  
  61.  
  62. return 0;
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement