Cut Ribbon

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;
}

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

时间: 2024-10-19 06:50:15

Cut Ribbon的相关文章

CodeForces 189A Cut Ribbon

Cut Ribbon Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 189A64-bit integer IO format: %I64d      Java class name: (Any) Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way

codeforces189A - Cut Ribbon DP

题意:给你一段绳子,让你把绳子切成 只有a,b,c组成的任意段,求得到最大段数; 解题思路:无穷背包 解题代码: 1 // File Name: 189a.cpp 2 // Author: darkdream 3 // Created Time: 2014年07月24日 星期四 08时11分26秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include&

为Ribbon界面的按钮添加自定义图像

上一节我们介绍了在Ribbon界面上添加按钮并响应按钮事件的过程,我们也看到了没有图像按钮看上去不是那么美观,因此添加上我们自己喜欢的图案成要当务之急.在为按钮添加图案,就要用到我们上节添加的另一个回调函数GetImage,它的声明如下: function GetImage(const ctrl: IDispatch): IDispatch; safecall; 根据微软的定义,Ctrl是要获取图像的按钮的IRibbonControl接口,我们要根据它的ID来判断谁要获取图片,返回值是图片对象的

使用vs2010创建MFC C++ Ribbon程序

Your First MFC C++ Ribbon Application with Visual Studio 2010 Earlier this month, I put together my first C++ sample in about a hundred years. I did that using win32 and Visual Studio 2010. Why? Well, a surprising number of folks are doing real work

Windows Ribbon for WinForms 开发实例

Windows Ribbon for WinForms 是 Windows Ribbon Framework 的一个 .NET 托管包装. 本实例将通过开发一个仿写字板的程序演示 Windows Ribbon for WinForms 的基本用法. 开发环境:Windows 10 64位 + Visual Studio 2015 下载 Windows Ribbon for WinForms 进入 http://windowsribbon.codeplex.com 页面,点击右上角的[downlo

shell脚本的使用---cut截取数据

linux之cut命令的用法 作者: 字体:[增加 减小] 类型:转载 时间:2013-10-03 我要评论 cut是一个选取命令,就是将一段数据经过分析,取出我们想要的.一般来说,选取信息通常是针对"行"来进行分析的,并不是整篇信息分析的 (1)其语法格式为: cut  [-bn] [file] 或 cut [-c] [file]  或  cut [-df] [file] 使用说明 cut 命令从文件的每一行剪切字节.字符和字段并将这些字节.字符和字段写至标准输出. 如果不指定 Fi

HDU 5452 Minimum Cut

Minimum Cut Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Total Submission(s): 315    Accepted Submission(s): 120 Problem Description Given a simple unweighted graph G (an undirected graph containing no loops nor

笔记:Spring Cloud Feign Ribbon 配置

由于 Spring Cloud Feign 的客户端负载均衡是通过 Spring Cloud Ribbon 实现的,所以我们可以直接通过配置 Ribbon 的客户端的方式来自定义各个服务客户端调用的参数. 全局配置 全局配置的方法非常简单,我们可以i直接使用 ribbon.<key>=<value>的方式来设置 ribbon 的各项默认参数,比如,修改默认的客户端调用超时时间示例如下,使用 yml 格式配置: ribbon: ConnectionTimeout: 500 ReadT

luoguP3690 【模板】Link Cut Tree (动态树)[LCT]

题目背景 动态树 题目描述 给定N个点以及每个点的权值,要你处理接下来的M个操作.操作有4种.操作从0到3编号.点从1到N编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor和.保证x到y是联通的. 1:后接两个整数(x,y),代表连接x到y,若x到Y已经联通则无需连接. 2:后接两个整数(x,y),代表删除边(x,y),不保证边(x,y)存在. 3:后接两个整数(x,y),代表将点X上的权值变成Y. 输入输出格式 输入格式: 第1行两个整数,分别为N和M,代表点数和操