Cut Ribbon
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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
5 5 3 2
output
2
input
7 5 5 2
output
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.

【题意】给你一根绳子称为d,现在要将绳子分成若干段,使得每一段的长度必须是a,b,c中的一个,求分得的最多段数。

【分析】简单DP,dp[i]代表切到当前位置获得的最大段数,慢慢更新即可。

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int N = 1e5+;
int n;
int a,b,c;
int dp[N];
void solve(int i,int x){
if(i-x==)dp[i]=max(dp[i],);
else if(i-x<)dp[i]=max(dp[i],);
else dp[i]=max(dp[i],dp[i-x]==?:dp[i-x]+);
}
int main(){
scanf("%d%d%d%d",&n,&a,&b,&c);
for(int i=;i<=n;i++){
solve(i,a);
solve(i,b);
solve(i,c);
}
printf("%d\n",dp[n]);
return ;
}

Codeforces Round #119 (Div. 2) Cut Ribbon(DP)的更多相关文章

  1. Codeforces Round #260 (Div. 2)C. Boredom(dp)

    C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  2. Codeforces Round #658 (Div. 2) D. Unmerge(dp)

    题目链接:https://codeforces.com/contest/1382/problem/D 题意 给出一个大小为 $2n$ 的排列,判断能否找到两个长为 $n$ 的子序列,使得二者归并排序后 ...

  3. Codeforces Round #471 (Div. 2) F. Heaps(dp)

    题意 给定一棵以 \(1\) 号点为根的树.若满足以下条件,则认为节点 \(p\) 处有一个 \(k\) 叉高度为 \(m\) 的堆: 若 \(m = 1\) ,则 \(p\) 本身就是一个 \(k\ ...

  4. 【Codeforces】Codeforces Round #374 (Div. 2) -- C. Journey (DP)

    C. Journey time limit per test3 seconds memory limit per test256 megabytes inputstandard input outpu ...

  5. Codeforces Round #652 (Div. 2) D. TediousLee(dp)

    题目链接:https://codeforces.com/contest/1369/problem/D 题意 最初有一个结点,衍生规则如下: 如果结点 $u$ 没有子结点,添加 $1$ 个子结点 如果结 ...

  6. Codeforces Round #247 (Div. 2) C. k-Tree (dp)

    题目链接 自己的dp, 不是很好,这道dp题是 完全自己做出来的,完全没看题解,还是有点进步,虽然这个dp题比较简单. 题意:一个k叉树, 每一个对应权值1-k, 问最后相加权值为n, 且最大值至少为 ...

  7. Codeforces Round #165 (Div. 1) Greenhouse Effect(DP)

    Greenhouse Effect time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  9. Codeforces Round #262 (Div. 2) 460C. Present(二分)

    题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...

随机推荐

  1. vijos 1448 校门外的树 树状数组

    描述 校门外有很多树,有苹果树,香蕉树,有会扔石头的,有可以吃掉补充体力的……如今学校决定在某个时刻在某一段种上一种树,保证任一时刻不会出现两段相同种类的树,现有两个操作:K=1,K=1,读入l.r表 ...

  2. C11性能之道:右值引用

    1.左值与右值 C++11中新增了一种类型,右值引用,标记为T &&. 首先来介绍什么是左值和右值,左值是指表达式结束后依旧存在的持久对象,而右值是指表达式结束之后就不再存在的临时对象 ...

  3. [Luogu 3178] HAOI2013 树上操作

    [Luogu 3178] HAOI2013 树上操作 一道比模板还简单的难以置信的裸HLD省选题. 大约是需要long long. #include <cstdio> #include & ...

  4. 【NOIP】提高组2015 斗地主

    [题意]按照斗地主出牌规则,给定手牌求出完的最少步数. [算法]模拟+搜索 [题解] 可以发现除了顺子,其它的出牌规则都和点数无关,只与同点数的牌数有关. 所以可以先暴力枚举要出哪些顺子,然后每一个出 ...

  5. 20、redis和memcached比较?

    1.Redis和Memcache都是将数据存放在内存中,都是内存数据库.不过memcache还可用于缓存其他东西,例如图片.视频等等: 2.Redis不仅仅支持简单的k/v类型的数据,同时还提供lis ...

  6. VS开发工具 因插件问题导致 已停止工作 解决办法

    解决方案如下:No1. 开始-->所有程序-->Microsoft Visual Studio 2012-->Visual Studio Tools-->VS2012 开发人员 ...

  7. linux下 vi中[noeol]以及出现 feff 的问题

    "uptime.py" [noeol] 69L, 2311C"system/uptime.py" 69L, 2312C 'noeol' 就是 'no end-o ...

  8. Part2-HttpClient官方教程-Chapter7-高级主题(Advanced topics) (HTTP Caching)

    原文链接 7.1 自定义客户端连接 在某些情况下,为了能够处理非标准的.不兼容的行为,可能需要自定义HTTP消息通过网络传输的方式,而不是使用HTTP参数.例如,对于web爬虫,可能有必要迫使Http ...

  9. 2017-2018-1 20179205《Linux内核原理与设计》第五周作业

    <Linux内核原理与设计>第五周作业 视频学习及操作分析 一.用户态.内核态和中断 内核态在CPU执行中对应高执行级别,执行级别为0级,具有特权指令,可以访问任意物理地址:用户态执行级别 ...

  10. LeetCode 19 Valid Parentheses

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...