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 ...
随机推荐
- MySQL的数据库备份
MySQL的数据库备份 备份的原因: 1.保证重要数据不丢失 2.数据转移 MySQL数据库备份方式: 1.方法1:在Sqlyog这种可视化工具中手动导出 2.方法2:直接拷贝物理文件(就是data文 ...
- Codeforces Round #617 (Div. 3) 补题记录
1296A - Array with Odd Sum 题意:可以改变数组中的一个数的值成另外一个数组中的数,问能不能使数组的和是个奇数 思路:签到,如果本来数组的和就是个奇数,那就OK 如果不是,就需 ...
- ASP.NET一般处理程序之网站请求过程
- 从零开始学 Java - 搭建 Spring MVC 记录云创的日子 第一章
2017年11月29日 来到新项目,需要用到Spring MVC ,那么我就开始记录我这次的学习. Spring MVC 框架是围绕一个 DispatcherServlet 来设计的,这个 Servl ...
- PHP 冷知识
1,执行Linux命令 <?php $a =`ls -a /`; // execute linux command echo '<pre>'.$a; 2.为变量起别名 <?ph ...
- C#在运行时自动引入正确的Dlls
设置程序Dlls的搜索路径 1.导入Native函数 /// <summary> /// 设置Dlls的搜索路径 /// </summary> /// <param na ...
- php文件上传与下载(附封装好的函数文件)
单文件上传前端页面 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- jQuery---width和height的方法
width和height的方法 //获取div的宽度 $("div").css("width", "400px"); console.log ...
- react-react中的css+评论组件
一个小案例,巩固有状态组件和无状态组件的使用 通过for循环生成多个组件 数据: CommentList = [ { user: '张三', content: '哈哈,沙发' }, { user: ' ...
- 直观获取redis cluster 主从关系
需求:还是redis-trib.rb脚本获取的信息不足或者太繁杂,这里给出更加直观的一种方法, 说明:已在4.x版本测试通过,3.x不可用. 原生的输出 (1adfa7f3...) keys slot ...