题目链接

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 a, b 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 n, a, b 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 a, b 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

题意:一块长为n的布,现在要把它剪开,只能剪成a, b, c这样的小块布,求最多能剪成多少块。。。

分析:就是一个需要刚好装满的完全背包问题,只有三种商品a, b, c,能取无限件物品,每件物品价值是1,求最大价值

#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
int n, a[3], dp[4010] = { 0 };
int main() {
cin >> n >> a[0] >> a[1] >> a[2]; dp[0] = 0;
for (int i = 1; i <= n; ++i) dp[i] = -inf;
for (int i = 1; i <= n; ++i)
for (int j = 0; j < 3; j++){
if (i >= a[j]) dp[i] = max(dp[i], dp[i - a[j]] + 1);
}
cout << dp[n];
return 0;
}

Codeforces 189 A. Cut Ribbon(DP 恰装满的完全背包问题)的更多相关文章

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

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

  2. CodeForces 176B - Word Cut 计数DP

    B. Word Cut   Let's consider one interesting word game. In this game you should transform one word i ...

  3. 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 ...

  4. 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 ...

  5. [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆)

    [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权 ...

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

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

  7. CodeForces 176B Word Cut dp

    Word Cut 题目连接: http://codeforces.com/problemset/problem/176/C Description Let's consider one interes ...

  8. CodeForces 176B Word Cut (计数DP)

    Word Cut Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit St ...

  9. 【CF 189A Cut Ribbon】dp

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

  10. Codeforces 189A. Cut Ribbon

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

随机推荐

  1. 有哪些可部署的, 无需编程的,基于WEB的数据可视化工具

    基于Web的数据可视化工具在当今数字化时代具有重要的作用,可以帮助企业和个人更好地理解和利用数据.以下是一些无需编程即可部署的基于Web的数据可视化工具,详细描述如下:Tableau Public: ...

  2. 地图选择器datav怎么使用?

    DataV 是一款基于阿里云的数据可视化产品,它提供了丰富的组件和功能,其中包括地图选择器.下面是一个详细的介绍: 1. 了解 DataV: - DataV 是一款强大的数据可视化工具,能够帮助用户将 ...

  3. Java8新特性之FlatMap&Reduce

    1.FlagMap // flatMap:接收一个T返回一个R,将一个元素转为一个新的流 ;R apply(T t); <R> Stream<R> flatMap(Functi ...

  4. 2024年 为什么不建议新人学习ABAP

    引言 每个应届生都希望自己有良好的职业发展,当他们发现前路难通时,便会寻找更好的出路. "转码"曾经是个很火热的话题.在互联网行业高速发展的年代,转行学代码,入职大厂,升职加薪,是 ...

  5. python操作mongodb基本使用

    使用pymongo,具体可以参考官方文档: 语法上基本和原生mongodb是一样的,所以非常容易入手... https://pymongo.readthedocs.io/en/stable/tutor ...

  6. MagicArray:像php一样,让Go业务代码不再卷!

    卷!一个字形容了当今码农行业的现状.一层一层的代码结构,一个一个dto,entity,vo,req,resp.这些对象越来越多,让码农们非常劳于奔命,加一个字段,改一个字段,影响面有多少.代码量也越来 ...

  7. rust 过程宏

    简介 Rust 编程语言里面有两种宏系统,一种是声明宏(Declarative Macros),另一种为过程宏(Procedural Macros).声明宏和过程宏是两种基本上完全不一样的宏系统,编写 ...

  8. 集群化部署ZabbixServer

    修改Zabbix-agent配置 1.修改配置文件 三台zabbix-Server上操作 vim /etc/zabbix/zabbix_agent2.conf Server=127.0.0.1 改成 ...

  9. 升级高版本springboot2.6.x:org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata

    升级springboot高版本2.6.x 项目使用到了springcloud的oauth2依赖,直接升级springboot项目版本为最新 2.6.8(2022年6月16日)将会报以下错误: org/ ...

  10. C++ 观察者模式实现

    观察者模式 主体(被观察者)通知一个或多个观察者状态改变/数据更新/事件发生. 描述 C++ 实现观察者模式有几个要点: 观察者都有一个共同的抽象基类 Listener,定义了一个纯虚接口 OnNot ...