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. C11工具类:时间处理

    C++11提供时间管理类,包括三种类型:时间间隔duration,时钟clocks,时间点time point. 1.记录时常的duration 1.1 原型 duration表示一段时间间隔,用来记 ...

  2. 【C++对象模型】第二章 构造函数语意学

    1.Default Constructor 当编译器需要的时候,default constructor会被合成出来,只执行编译器所需要的任务(将members适当初始化). 1.1  带有 Defau ...

  3. Apache 文件服务器

    1.安装apache服务器yum install httpd 2.启动httpd服务service httpd start 3.查看httpd服务器的版本httpd -v 4.修改访问端口和文件路径, ...

  4. 【bzoj3476-懒惰的奶牛】线段树

    题解: 感觉这题和别人的做法不一样...呵呵呵...调了一百年.. 设家坐标为(a,b),对于每个点(x,y),可以转化为|a-x|+|b-y|<=k 对于每个点,它的影响范围是一个菱形(也就是 ...

  5. 【BZOJ1598】牛跑步 [A*搜索]

    牛跑步 Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Description BESSIE准备用从牛棚跑到池塘的方 ...

  6. 汕头市队赛SRM 20 T3 灵魂觉醒

    背景 自从芽衣.布洛妮娅相继灵魂觉醒之后,琪亚娜坐不住了.自己可是第一个入驻休伯利安号的啊!于是她打算去找德丽莎帮忙,为她安排了灵魂觉醒的相关课程. 第一天,第一节课. “实现灵魂觉醒之前,你需要先将 ...

  7. MyBatis 系列五 之 延迟加载、一级缓存、二级缓存设置

    MyBatis的延迟加载.一级缓存.二级缓存设置 首先我们必须分清延迟加载的适用对象 延迟加载 MyBatis中的延迟加载,也称为懒加载,是指在进行关联查询时,按照设置延迟加载规则推迟对关联对象的se ...

  8. vue实现微信对话

    因为项目中需要实现仿微信对话功能,于是抽空实现了下,主要是h5的canvas的把图片和文字绘制到画布上 原文来自我的个人博客:http://lvhww.com/index.php/archives/6 ...

  9. OSI与TCP/IP各层的结构与功能,都有哪些协议

    前言: 今天更新一下计算机网络的一些非常重要的知识,可能很多人都不知学计算机网络有什么用,我想说的是它真的比较重要,像咱们学校只要是学计算机这个专业都要学习这门课程.另外大家要是去一些像BAT,阿里, ...

  10. 修改ES使用root用户运行

    默认ES不允许使用root用户运行,如果使用root会报如下图的错误: ,通常建议创建elsearch用户并使用该用户运行ES.但如果必须使用root用户时,按如下设置即可: 1.启动是使用如下命令 ...