Advertisement
apl-mhd

A. Cut Ribbon

Apr 18th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <climits>
  5. #define MAX 50
  6. #define ROW 4000;
  7. #define COL 4000;
  8.  
  9. int dp[4010];
  10.  
  11. void  init(int n){
  12.  
  13.     dp[0]=0;
  14.  
  15.     for (int i=1; i<n; i++) {
  16.  
  17.  
  18.         dp[i] = -1;
  19.  
  20.     }
  21. }
  22.  
  23. using namespace std;
  24.  
  25.  
  26. int maximum(int a[], int n, int i){
  27.  
  28.  
  29.     if(n<0 || i>2)
  30.         return INT_MIN;
  31.  
  32.  
  33.  
  34.     if(dp[n] != -1)
  35.         return dp[n];
  36.  
  37.  
  38.  
  39.     return dp[n] = max(1 + maximum(a, n - a[i], i), maximum(a, n, i + 1));
  40.  
  41. }
  42.  
  43. int main() {
  44.  
  45.  
  46.     // freopen("input.txt","r", stdin);
  47.  
  48.     int n;
  49.     int  arr[3];
  50.  
  51.     cin>>n>>arr[0]>>arr[1]>>arr[2];
  52.  
  53.     init(n+10);
  54.  
  55.     cout<<maximum(arr,n,0);
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement