Maruf_Hasan

DIv3E

Mar 13th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. /*If you want something you've never had, you have to do something you never did.*/
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6.  
  7. #define pb push_back
  8. #define ll long long
  9. #define pii pair<ll,ll>
  10. #define pll pair<ll,ll>
  11. #define M 100007
  12. #define INF 1e9
  13. #define INFL 1e18
  14. #define PI acos(-1)
  15. #define mp make_pair
  16. #define fast_in_out ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  17. //const ll fx[]= {+1,-1,+0,+0};
  18. //const ll fy[]= {+0,+0,+1,-1};
  19. //const ll fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
  20. //const ll fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
  21. //const ll fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
  22.  
  23. int arr[2110];
  24. int dp[2110][2110];
  25. int n,l,h,r;
  26. int myfunc(int i,int time)
  27. {
  28.  
  29. if(i==n)
  30. {
  31. return time>=l & time<=r;
  32. }
  33. if(dp[i][time]!=-1)
  34. return dp[i][time];
  35. int x1=0,x2=0;
  36. if(time>=l && time<=r)
  37. {
  38.  
  39. x1=1+myfunc(i+1,(time+arr[i])%h);
  40. x2=1+myfunc(i+1,(time+arr[i]-1)%h);
  41. }
  42. else
  43. {
  44. x1=myfunc(i+1,(time+arr[i])%h);
  45. x2=myfunc(i+1,(time+arr[i]-1)%h);
  46. }
  47. dp[i][time]=max(x1,x2);
  48. return dp[i][time];
  49. }
  50.  
  51. int main()
  52. {
  53. fast_in_out;
  54. cin>>n>>h>>l>>r;
  55. for(int i=0;i<n;i++)
  56. {
  57. cin>>arr[i];
  58. }
  59. memset(dp,-1,sizeof dp);
  60. int ans=myfunc(0,0);
  61. cout<<ans<<endl;
  62. return 0;
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment