码迷,mamicode.com
首页 > 其他好文 > 详细

Cut Ribbon

时间:2020-02-18 13:04:42      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:The   include   single   ring   ant   each   exist   tee   with   

Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions:

  • After the cutting each ribbon piece should have length ab or c.
  • After the cutting the number of ribbon pieces should be maximum.

Help Polycarpus and find the number of ribbon pieces after the required cutting.

Input

The first line contains four space-separated integers nab and c (1 ≤ n, a, b, c ≤ 4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers ab and c can coincide.

Output

Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.

Examples
input
Copy
5 5 3 2
output
Copy
2
input
Copy
7 5 5 2
output
Copy
2
Note

In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.

In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.

 


 

 

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define mod 998244353
using namespace std;
int dir[4][2] = { {0,1},{0,-1},{-1,0},{1,0} };


int main() 
{
    int n;
    cin >> n;
    vector<int> a(3),dp(n+1);
    for (int i = 0; i < 3; i++)
        cin >> a[i];
    sort(a.begin(), a.end());
    if (a[0] <= n) dp[a[0]] = 1;
    if (a[1] <= n) dp[a[1]] = 1;
    if (a[2] <= n) dp[a[2]] = 1;
    for (int i = 1; i <= n; i++)
    {
        int ans = dp[i];
        if (i > a[0] && dp[i - a[0]] != 0) ans = max(ans, dp[i - a[0]] + 1);
        if (i > a[1] && dp[i - a[1]] != 0) ans = max(ans, dp[i - a[1]] + 1);
        if (i > a[2] && dp[i - a[2]] != 0) ans = max(ans, dp[i - a[2]] + 1);
        dp[i] = ans;
    }
    cout << dp[n] << endl;
    return 0;
}

 

Cut Ribbon

标签:The   include   single   ring   ant   each   exist   tee   with   

原文地址:https://www.cnblogs.com/dealer/p/12325505.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!