题目链接

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. Modbus转PROFINET网关 TS-180

    TS-180实现 PROFINET 网络与串口网络之间的数据通信.三串口可分别连接具有 RS232 或 RS485 接口的设备到PROFINET 网络,三串口相同,全为 RS232 或RS485.即将 ...

  2. Go笔记(2)-5种运算符总结

    运算符 (1)算术运算符 (2)关系运算符 (3)逻辑运算符 (4)位运算符 (5)赋值运算符

  3. .net下优秀的日志框架Serilog,你用上了吗?强烈推荐

    在 .NET 开发中,Serilog 是一款广受欢迎的日志库,它提供了强大的日志记录功能,具有丰富的特性和高度的可扩展性.Serilog 的优秀之处包括: 可扩展性: Serilog 可以轻松扩展以满 ...

  4. [CF1854E] Game Bundles

    题目描述 Rishi is developing games in the 2D metaverse and wants to offer game bundles to his customers. ...

  5. [ABC261E] Many Operations

    Problem Statement We have a variable \(X\) and \(N\) kinds of operations that change the value of \( ...

  6. [USACO2022OPENS] Visits

    题目描述 Bessie 的 \(N\)(\(2\le N\le 10^5\))个奶牛伙伴(编号为 \(1\cdots N\))每一个都拥有自己的农场.对于每个 \(1\le i\le N\),伙伴 i ...

  7. Hive SQL之表与建表

    数据类型:  建表 create database itheima; --1.创建一张表 -- 表名 --字段 名称 类型 顺序 --字段之间的分隔符 create table itheima.t_a ...

  8. springBoot——整合mybatis

    spring整合mybatis springBoot整合mybaits 配置文件 spring: datasource: url: jdbc:mysql://localhost:3306/test d ...

  9. 【OpenVINO 】在 MacOS 上编译 OpenVINO C++ 项目

    前言 英特尔公司发行的模型部署工具OpenVINO模型部署套件,可以实现在不同系统环境下运行,且发布的OpenVINO 2023最新版目前已经支持MacOS系统并同时支持在苹果M系列芯片上部署模型.在 ...

  10. 关于向上转型以及向下转型、instanceof的一些应用。

    一.前言 在Java编程中,我们常常遇到各种类型转换的情况,尤其是在处理继承关系的类时.本文将深入探讨Java中的向上转型(upcasting).向下转型(downcasting)以及instance ...