Advertisement
apl-mhd

CF A. Cut Ribbon

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