Codeforces 189 A. Cut Ribbon(DP 恰装满的完全背包问题)
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 恰装满的完全背包问题)的更多相关文章
- Codeforces 189A:Cut Ribbon(完全背包,DP)
time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...
- CodeForces 176B - Word Cut 计数DP
B. Word Cut Let's consider one interesting word game. In this game you should transform one word i ...
- 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 ...
- 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 ...
- [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆)
[BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权 ...
- [CF189A]Cut Ribbon(完全背包,DP)
题目链接:http://codeforces.com/problemset/problem/189/A 题意:给你长为n的绳子,每次只允许切a,b,c三种长度的段,问最多能切多少段.注意每一段都得是a ...
- CodeForces 176B Word Cut dp
Word Cut 题目连接: http://codeforces.com/problemset/problem/176/C Description Let's consider one interes ...
- CodeForces 176B Word Cut (计数DP)
Word Cut Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit St ...
- 【CF 189A Cut Ribbon】dp
题目链接:http://codeforces.com/problemset/problem/189/A 题意:一个长度为n的纸带,允许切割若干次,每次切下的长度只能是{a, b, c}之一.问最多能切 ...
- Codeforces 189A. Cut Ribbon
题目链接:http://codeforces.com/problemset/problem/189/A 题意: 给你一个长度为 N 的布条, 再给你三个长度 a, b , c.你可以用剪刀去剪这些布条 ...
随机推荐
- 基于OpenAi通用特定领域的智能语音小助手
无穷尽的Q&A 钉钉...钉钉... 双双同学刚到工位,报销答疑群的消息就万马纷沓而来.她只能咧嘴无奈的摇摇头.水都还没有喝一口就开始"人工智能"的去回复.原本很阳光心情开 ...
- 用友NC产品接口开发,通过轻易云数据集成平台快速调用
通过用友NC产品的 UAP V63平台.插件相关处理.相关业务逻辑处理课程目标与要求课程内容课程目标与要求业务逻辑处理外部系统信息设置节点新建外部系统默认匹配规则:仅按对照表:外部系统数据与UAP.接 ...
- 什么是Session;request.getSession().setAttribute()
Session:会话控制,是服务器为了保存用户状态而创建的一个特殊的对象.=>用于存储信息的一个对象 当我们在服务端使用session时,首先要获取session,下面这个图就对服务器获取ses ...
- Hive SQL之表与建表
数据类型: 建表 create database itheima; --1.创建一张表 -- 表名 --字段 名称 类型 顺序 --字段之间的分隔符 create table itheima.t_a ...
- RISC-V系列单片机快速入门指南
如何获取芯片开发资料 方法一:按型号选择 我们更推荐采用按型号选择的方法,获取所对应型号芯片的开发资料,这能有效降低错误使用资料的风险! 沁恒官网首页的产品中心,点击青稞 RISC-V 通用系列,可跳 ...
- 什么是 MySQL JDBC 连接池中最高效的连接检测语句?
在回答这个问题之前,首先我们看看 MySQL 中有哪些常用的 JDBC 连接池: c3p0 DBCP Druid Tomcat JDBC Pool HikariCP 这些连接池中,c3p0 是一个老牌 ...
- 【Python】【OpenCV】轮廓检测
Code: 1 import cv2 2 import numpy as np 3 4 img = np.zeros((200, 200), dtype=np.uint8) 5 img[50:150, ...
- 从零玩转Java和word模板-从零玩转java和word模板
title: 从零玩转Java和word模板 date: 2021-12-22 18:38:14.086 updated: 2021-12-22 18:38:14.086 url: https://w ...
- IDEA插件(1 UI美化)
一.IDEA 插件怎么安装?(图文讲解) IntelliJ IDEA 支持丰富的插件,熟练使用相关插件,能够有效提高我们的开发效率以及用户体验.那么,要如何在 IDEA 中安装插件呢?这里有两种方式: ...
- Shell的概念、shebang、bash的概念
什么是shell shell的作用是 解释执行用户输入的命令或程序等 用户输入一条命令,shell就解释一条 键盘输入命令,Linux给与响应的方式,称之为交互式 linux的计算机是如何跟用户进行交 ...