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[][] = { {,},{,-},{-,},{,} }; int main()
{
int n;
cin >> n;
vector<int> a(),dp(n+);
for (int i = ; i < ; i++)
cin >> a[i];
sort(a.begin(), a.end());
if (a[] <= n) dp[a[]] = ;
if (a[] <= n) dp[a[]] = ;
if (a[] <= n) dp[a[]] = ;
for (int i = ; i <= n; i++)
{
int ans = dp[i];
if (i > a[] && dp[i - a[]] != ) ans = max(ans, dp[i - a[]] + );
if (i > a[] && dp[i - a[]] != ) ans = max(ans, dp[i - a[]] + );
if (i > a[] && dp[i - a[]] != ) ans = max(ans, dp[i - a[]] + );
dp[i] = ans;
}
cout << dp[n] << endl;
return ;
}

Cut Ribbon的更多相关文章

  1. Codeforces Round #119 (Div. 2) Cut Ribbon(DP)

    Cut Ribbon time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  2. Codeforces Round #119 (Div. 2)A. Cut Ribbon

    A. Cut Ribbon time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. Codeforces 189A:Cut Ribbon(完全背包,DP)

    time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...

  4. [CF189A]Cut Ribbon(完全背包,DP)

    题目链接:http://codeforces.com/problemset/problem/189/A 题意:给你长为n的绳子,每次只允许切a,b,c三种长度的段,问最多能切多少段.注意每一段都得是a ...

  5. 【CF 189A Cut Ribbon】dp

    题目链接:http://codeforces.com/problemset/problem/189/A 题意:一个长度为n的纸带,允许切割若干次,每次切下的长度只能是{a, b, c}之一.问最多能切 ...

  6. CF 189A Cut Ribbon

    #include<bits/stdc++.h> using namespace std; const int maxn = 4000 + 131; int n, a, b, c; int ...

  7. Codeforces 189A. Cut Ribbon

    题目链接:http://codeforces.com/problemset/problem/189/A 题意: 给你一个长度为 N 的布条, 再给你三个长度 a, b , c.你可以用剪刀去剪这些布条 ...

  8. Codeforces Round #119 (Div. 2)

    A. Cut Ribbon \(f(i)\)表示长为\(i\)的布条最多可以剪几段. B. Counting Rhombi \(O(wh)\)枚举中心计算 C. Permutations 将序列一映射 ...

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

    Your First MFC C++ Ribbon Application with Visual Studio 2010 Earlier this month, I put together my ...

随机推荐

  1. 阿里云IIS服务器SSL证书安装

    一.前提条件 申请证书时需要选择 系统自动创建CSR. 申请证书时如果选择手动创建CSR,则不会生成证书文件.您需要选择其他服务器下载.crt证书文件后,使用openssl命令将.crt文件的证书转换 ...

  2. Qt多线程实现思路一

    实现一个线程开启时,时间计时器任然能够计数,两路独立工作的线程功能.从类的帮助文件中可以看到如下信息,静态公共成员函数和保护类型的函数,在静态函数中有睡眠函数msleep毫秒级,sleep秒级,usl ...

  3. 深入浅出Mybatis系列四-配置详解之typeAliases别名(mybatis源码篇)

    注:本文转载自南轲梦 注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 上篇文章<深入浅出Mybatis系列(三)---配置详解之properties ...

  4. qsort 与sort 对结构体排序实例

    qsort 与sort 对结构体排序实例 #include<bits/stdc++.h> using namespace std; typedef struct { string book ...

  5. JavaScript 15 Ajax异步登陆

    /** * Created by KING on 2017/11/28. */ var g_xhr_ui;var g_xhr_login;var g_id; $(document).ready(fun ...

  6. centos因为安装花生壳而无法登录系统的问题

    服务器安装 phddns 花生壳 启动失败,一直卡在启动进度条页面. 解决办法 1.按F5查看卡在什么位置, 2.查看解决方法:程序卡住的情况下,直接备份资料后,卸载程序重启就可以了. 3.进入到si ...

  7. H3C 静态路由

    一.静态路由简介 静态路由是一种特殊的路由,由管理员手工配置.当网络结构比较简单时,只需配置静态路由就可以使网络正常工作. 静态路由不能自动适应网络拓扑结构的变化.当网络发生故障或者拓扑发生变化后,必 ...

  8. Springboot 中的配置文件

    Spring Boot提供了两种常用的配置文件,分别是properties文件和yml文件.他们的作用都是修改Spring Boot自动配置的默认值. 技术:yaml.properties语法,Con ...

  9. 网络编程UDP、TCP详解

    网络编程   网络编程主要用于解决计算机与计算机(手机.平板-)之间的数据传输问题. 1.InetAddress(IP类)   方法: 方法 描述 getLocalHost() 获取本机的IP地址对象 ...

  10. 2020牛客寒假算法基础集训营6 I.导航系统 (最小生成树)

    https://ac.nowcoder.com/acm/contest/3007/I 题中给定的图必定是一棵树 容易发现,如果将输入的N(N-1)个距离看做N(N-1)条无向边的话,那么如果数据合法, ...