Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n,price[51],isavilable[51],dp[1001][51];
  4. int func(int i, int value)
  5. {
  6. if(i>=n)
  7. {
  8. if(value == 0) return 1;
  9. else return 0;
  10. }
  11.  
  12. if(value == 0) return 1;
  13.  
  14.  
  15. if(dp[value][i] != -1)
  16. return dp[value][i];
  17.  
  18. int result = 0;
  19.  
  20. for(int j = 0; j <= isavilable[i]; j++)
  21. {
  22. if(value-price[i]*j >= 0)
  23. result = (result%100000007 + func(i+1,value-(price[i]*j)))%100000007;
  24. }
  25.  
  26. return dp[value][i]=result;
  27. }
  28. int main()
  29. {
  30. int T,value,cases=0;
  31. scanf("%d",&T);
  32. while(T--)
  33. {
  34. scanf("%d %d", &n, &value);
  35. for(int i = 0; i <= value+1; i++)
  36. {
  37. for(int j = 0; j <= n; j++)
  38. {
  39. dp[i][j]= -1;
  40. }
  41. }
  42. for(int i = 0; i < n; i++) scanf("%d",&price[i]);
  43. for(int i = 0; i < n; i++) scanf("%d",&isavilable[i]);
  44. printf("Case %d: %d\n",++cases,func(0,value));
  45. }
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement