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 ...
随机推荐
- 问题 C: To Fill or Not to Fill
#include <cstdio> #include <vector> #include <algorithm> #include <cmath> us ...
- Mysql常见注入
Mysql显错注入 1.判断注入类型为字符型:http://219.153.49.228:43074/new_list.php?id=tingjigonggao' and 1=1 --+2.判断字段为 ...
- pythonCSV内置模块应用
一.Python内置模块CSV CSV,即逗号分隔值(也称字符分隔值,因为分隔符可以不是逗号),是一种常用的文本格式,用以存储表格数据,包括数字或者字符.如下图所示: CSV类似于Excel格式 很多 ...
- vue里使用element饿了么的el-menu+vue-router实现路由跳转的两种方法
最近准备写一个echarts的可视化展示案例,首先用vue-cli3创建了一个项目(好像vue-cli4也出来,感觉变化不大,就没升级了) 然后,开始配置路由↓下面是我的router.js文件 imp ...
- centos7上python3.6.5的安装及卸载
前言 最近开始安装配置公司给我的台式机,加上刚刚购买的ECS,处女座的我,环境前前后后大概装了有十来次吧,之前装总是临时网上找教程,但是装下来总是感觉有点别扭,当时服务器装的是3.6.5,虚拟机装的是 ...
- 48.Python中ORM模型实现mysql数据库基本的增删改查操作
首先需要配置settings.py文件中的DATABASES与数据库的连接信息, DATABASES = { 'default': { 'ENGINE': 'django.db.backends.my ...
- 原生JS操作class 极致版
// 获取class function getClass(el) { return el.getAttribute('class') } // 设置class function setClass(el ...
- MySQL的DML语言(增删改)
MySQL的DML语言(增删改) 补充说明,外键:不要使用外键,一切外键概念都在应用层解决. 补充说明,数据库的列,也就是字段名,尽量带上飘符号` 数据库存在的意义:数据存储和数据管理. 数据库:行( ...
- LaTeX技巧003:实现一个章标题
代码如下: \documentclass[11pt]{book} \usepackage{graphicx} \usepackage{CJKfntef} \usepackage{color} \mak ...
- 2020牛客寒假算法基础集训营1 F-maki和tree
链接:https://ac.nowcoder.com/acm/contest/3002/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...