题目链接

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. C/C++ Zlib库封装MyZip压缩类

    Zlib是一个开源的数据压缩库,提供了一种通用的数据压缩和解压缩算法.它最初由Jean-Loup Gailly和Mark Adler开发,旨在成为一个高效.轻量级的压缩库,其被广泛应用于许多领域,包括 ...

  2. Django学习(一) 之 环境搭建

    写在前面 最近比较迷AI绘图,那就上个图吧,我感觉还挺好看的. 可能会有人说,之前不一致分享的是flask吗,怎么突然改到django了? 这个问题问得好,开发环境遇到了一些小困难! 不过django ...

  3. Bash—source命令&export命令&bashrc文件

    当不使用 source 命令执行脚本时,会创建一个子 shell,在该子 shell 中执行完脚本后退出子 shell.不是用 export 定义的变量只对该 shell 有效,对子 shell 是无 ...

  4. Linux中execl函数详解与日常应用!

    Linux中execl函数详解与日常应用 execl是Linux系统中的一个系统调用,用于执行指定路径下的可执行文件.本文将详细介绍execl函数的使用方法和参数含义,并探讨其在日常开发中的常见应用场 ...

  5. typora写作

    平时写博客,一般采用typora,但是字体颜色和上传到博客园的图片大小和居中问题,总是很糟糕,偶然发现输入法里面还有自定义的短语,能够解决这个问题. <p><img src=&quo ...

  6. .net 获取客户端真实ip

    Nginx 如何设置 情况1 在只有1层nginx代理的情况下,设置nginx配置"proxy_set_header X-Forwarded-For $remote_addr;". ...

  7. Android阅读器之文本、图片和表格测量

    文章摘要 本文将介绍如何在Android开发中实现文本.图片和表格的测量.我们将使用Android Studio和Java语言,并利用Android SDK中的相关类库. 正文 文本测量 在Andro ...

  8. 字节国际化TnS算法实习的碎碎念

    Motivation 在保研之后,我和南大的导师投了一篇个性化联邦学习的CVPR作为毕设.之后感觉就没什么事了,于是想着找个实习吧,第一个想法就是去字节实习,也只投了字节(别学我,还是多投一些哈哈,找 ...

  9. 华企盾DSC可能涉及的Linux命令

    掌握Linux系统的基本命令 详细使用请参考:Linux命令大全 uname 查看系统信息 wget 文件下载 chmod 改变文件或目录权限 ls 显示指定工作目录下的内容及属性信息 cd 切换当前 ...

  10. 数字孪生技术助力GIS行业实现视效升级

    在当今数字化时代,数字孪生技术正逐渐成为各行各业的一项核心技术,而地理信息系统(GIS)行业也不例外.数字孪生和GIS的结合,为地理空间数据的采集.管理.分析和可视化提供了全新的可能性,使GIS行业得 ...