Cut Ribbon
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.
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.
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
5 5 3 2
2
7 5 5 2
2
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define mod 998244353
using namespace std;
int dir[][] = { {,},{,-},{-,},{,} }; int main()
{
int n;
cin >> n;
vector<int> a(),dp(n+);
for (int i = ; i < ; i++)
cin >> a[i];
sort(a.begin(), a.end());
if (a[] <= n) dp[a[]] = ;
if (a[] <= n) dp[a[]] = ;
if (a[] <= n) dp[a[]] = ;
for (int i = ; i <= n; i++)
{
int ans = dp[i];
if (i > a[] && dp[i - a[]] != ) ans = max(ans, dp[i - a[]] + );
if (i > a[] && dp[i - a[]] != ) ans = max(ans, dp[i - a[]] + );
if (i > a[] && dp[i - a[]] != ) ans = max(ans, dp[i - a[]] + );
dp[i] = ans;
}
cout << dp[n] << endl;
return ;
}
Cut Ribbon的更多相关文章
- 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 ...
- Codeforces 189A:Cut Ribbon(完全背包,DP)
time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...
- [CF189A]Cut Ribbon(完全背包,DP)
题目链接:http://codeforces.com/problemset/problem/189/A 题意:给你长为n的绳子,每次只允许切a,b,c三种长度的段,问最多能切多少段.注意每一段都得是a ...
- 【CF 189A Cut Ribbon】dp
题目链接:http://codeforces.com/problemset/problem/189/A 题意:一个长度为n的纸带,允许切割若干次,每次切下的长度只能是{a, b, c}之一.问最多能切 ...
- CF 189A Cut Ribbon
#include<bits/stdc++.h> using namespace std; const int maxn = 4000 + 131; int n, a, b, c; int ...
- Codeforces 189A. Cut Ribbon
题目链接:http://codeforces.com/problemset/problem/189/A 题意: 给你一个长度为 N 的布条, 再给你三个长度 a, b , c.你可以用剪刀去剪这些布条 ...
- Codeforces Round #119 (Div. 2)
A. Cut Ribbon \(f(i)\)表示长为\(i\)的布条最多可以剪几段. B. Counting Rhombi \(O(wh)\)枚举中心计算 C. Permutations 将序列一映射 ...
- 使用vs2010创建MFC C++ Ribbon程序
Your First MFC C++ Ribbon Application with Visual Studio 2010 Earlier this month, I put together my ...
随机推荐
- HDFS的扩容
一.扩容 1.1横向扩容:加节点 https://www.cnblogs.com/the-roc/p/12362926.html 1.2纵向扩容:加硬盘 二.纵向扩容 2.1添加硬盘 2.2在关 ...
- 【Linux远程连接工具】Xshell、Xftp家庭/学生版(免费使用)
注:Xshell.Xftp家庭/学生版无需激活,可以免费使用! 1.步骤一: 官网下载地址:https://www.netsarang.com/zh/ 选择[所有下载]->[家庭/学校免费] ...
- Socket之UDP
相对于TCP/IP来说,UDP更像是发快递和写信,不需要判断和对方是否连通就可以发送,而TCP/IP必须确认连通之后才可以发送,这样UDP通讯其实不能严格按照TCP/IP的说法区分服务器和客户端,对于 ...
- 0级搭建类001-RedHat Enterprise Linux 8 安装(RHEL 8) 公开
项目文档引子系列是根据项目原型,制作的测试实验文档,目的是为了提升项目过程中的实际动手能力,打造精品文档AskScuti. 项目文档引子系列目前不对外发布,仅作为博客记录.如学员在实际工作过程中需提前 ...
- js异步执行 按需加载 三种方式
js异步执行 按需加载 三种方式 第一种:函数引用 将所需加载方法放在匿名函数中传入 //第一种 函数引用 function loadScript(url,callback){ //创建一个js va ...
- Vuejs中created和mounted的区别
created:在模板渲染成html前调用,即通常初始化某些属性值,然后再渲染成视图. mounted:在模板渲染成html后调用,通常是初始化页面完成后,再对html的dom节点进行一些需要的操作
- PHP实现微信公众号分享接口
还是一贯风格:用代码说话!!! <?php class ShareModel extends BaseModel { var $appId = APPID; var $appSecret = A ...
- Java基本语法--控制台输入(Scanner类)
通过Scanner类获取用户输入时,控制台会一直等待用户的输入,可以输入不同类型的值.本篇博客主要讲解从控制台输入值,即Scanner类的使用方法. Api文档中关于Scanner类的构造方法 键盘输 ...
- mysql视图的创建、基本操作、作用
一.mysql视图的创建 作用:提高了重用性,就像一个函数.如果要频繁获取user的name和goods的name.就应该使用以下sql语言.示例: 先创建3张表 1.1user表 1.2goods表 ...
- 逗号运算符与括号 - C语言
例1 int x; int a=(x=2),12;// 赋值优先级高于逗号,相当于a=x=2,12是多余的 printf("a=%d",a); 结果:a=2 例2 int x; i ...