题目链接

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. 线上ES集群参数配置引起的业务异常案例分析

    作者:vivo 互联网数据库团队- Liu Huang 本文介绍了一次排查Elasticsearch node_concurrent_recoveries 引发的性能问题的过程. 一.故障描述 1.1 ...

  2. 汇报工作与众不同:在PPT中展示Datainside动态图表

    题目要求了解在PPT中展示Datainside动态图表,下面是关于该主题的详细介绍. 内容可视化:概念与定义 内容可视化(Data Visualization)是将数据以图形或其他视觉形式呈现的过程, ...

  3. 浅析MySQL代价模型:告别盲目使用EXPLAIN,提前预知索引优化策略

    背景 在 MySQL 中,当我们为表创建了一个或多个索引后,通常需要在索引定义完成后,根据具体的数据情况执行 EXPLAIN 命令,才能观察到数据库实际使用哪个索引.是否使用索引.这使得我们在添加新索 ...

  4. SpringBoot项目启动过程动态修改接口请求路径

    背景 最近遇到一个技术需求,需要对其他多个已有的服务进行整合打包为一个整体的服务,项目启动过程发现一个问题,在controller层多个服务之间存在相同的RequestMapping接口请求路径,导致 ...

  5. SpringCore完整学习教程7,入门级别

    本章可以说是完结,下一章可能讲kotlin+springboot 本章从第九章开始: 9. Creating Your Own Auto-configuration 如果您在开发共享库的公司工作,或者 ...

  6. Java如何连接Mysql数据库

    条件:eclipse.MySQL .jdbc驱动 eclipse.MySQL 的安装.下载jdbc连接驱动 eclipse的安装去官网下载并安装 MySQL .jdbc的下载地址请访问:https:/ ...

  7. 2023年度低代码平台企业TOP50榜单公布—以开源起家的JeecgBoot格外亮眼

    近日,中国科学院主管.科学出版社主办的国家级核心期刊<互联网周刊>联合eNet研究院.德本咨询评选的<2023低代码企业50强>榜单正式公布.这一榜单的公布引起了业内外的广泛关 ...

  8. 【源码系列#04】Vue3侦听器原理(Watch)

    专栏分享:vue2源码专栏,vue3源码专栏,vue router源码专栏,玩具项目专栏,硬核推荐 欢迎各位ITer关注点赞收藏 语法 侦听一个或多个响应式数据源,并在数据源变化时调用所给的回调函数 ...

  9. PersistenceException、ReflectionException、IllegalArgumentException、wrapException持久性异常 反射异常 非法参数异常 包装异常

    PersistenceException.ReflectionException.IllegalArgumentException.wrapException wrapException 持久性异常 ...

  10. 变更(重命名)AD域名称

    文章来自:https://blog.51cto.com/sxleilong/1377731 示例将域名contoso.com重命名为Corp.sxleilong.com 查看当前fsmo的5个角色. ...