题目链接

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. SpringBoot + 通义千问 + 自定义React组件,支持EventStream数据解析!

    一.前言 大家好!我是sum墨,一个一线的底层码农,平时喜欢研究和思考一些技术相关的问题并整理成文,限于本人水平,如果文章和代码有表述不当之处,还请不吝赐教. 最近ChatGPT非常受欢迎,尤其是在编 ...

  2. 稳了,终于可以通过外网访问 Sealos 中的数据库了!

    喜大普奔,Sealos 中的数据库功能现已全面升级,支持外网访问! 现在你可以从互联网的任何地方访问 Sealos 中的数据库,无论您的应用部署在何种环境,现在都可以轻松通过外网连接到 Sealos ...

  3. [CSAPP、APUE、UNP]文件、IO

    <鸟哥的Linux私房菜:基础学习篇(第四版)> 第5章 Linux的文件权限与目录配置 第6章 LInux文件与目录管理(正在进行) <CSAPP> 第10章 系统级IO 1 ...

  4. 生成模型的两大代表:VAE和GAN

    生成模型 给定数据集,希望生成模型产生与训练集同分布的新样本.对于训练数据服从\(p_{data}(x)\):对于产生样本服从\(p_{model}(x)\).希望学到一个模型\(p_{model}( ...

  5. SpringBoot整合Filter过滤器

    话不多说,直接上核心代码 1.先创建一个Filter类 package com.qbb.reggie.filter; import com.alibaba.fastjson.JSON; import ...

  6. ES集群搭建和Kibana管理集群

    搭建实例 先复制2份解压后的完整目录,将里面的data和log删除. elasticsearch-6.8.23-node2 elasticsearch-6.8.23-node3 修改3个实例的配置文件 ...

  7. Scrapy-CrawlSpider爬虫类使用案例

    CrawlSpider类型的爬虫会根据指定的rules规则自动找到url比自动爬取. 优点:适合整站爬取,自动翻页爬取 缺点:比较难以通过meta传参,只适合一个页面就能拿完数据的. import s ...

  8. 【C#】【WinForm】MDI窗体

    MDI窗体的相关学习使用 1.设置MDI父窗体 在属性中找到IsMdiContainer选项,设置为True 2.添加MDI子窗体,在项目中依次选择添加->窗体,然后一直默认即可 添加后的项目目 ...

  9. selenium之三种等待,强制等待、隐式等待和显式等待

    显式等待 presence_of_element_locatedpresence_of_all_elements_locatedvisibility_of_any_elements_located   ...

  10. Vue学习笔记-生命周期

    整体页面代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...