Codeforces 189A. Cut Ribbon
题目链接:http://codeforces.com/problemset/problem/189/A
题意:
给你一个长度为 N 的布条, 再给你三个长度 a, b , c.你可以用剪刀去剪这些布条, 但是每次剪完后, 布条的长度必须是 a 或者 b 或者 c, 问按照这个规则, 最多可以把这个布条剪成几段.
思路:
上述问题可以换一种说法, 这里有无线个长度为 a, b, c的布条, 让你选择最多的个数, 使得其连接起来长度恰好为 N.这很显然是根基础的完全背包的拓展问题.所以只解套用模板就好.
dp[i] = max( dp[i], dp[ i - v[j] ] + w[j] ).
代码:
#include <iostream>
#include <algorithm> using namespace std;
typedef long long LL;
const int MAXN = ;
int dp[MAXN + ] = {}; int main() {
ios_base::sync_with_stdio(); cin.tie();
int n, abc[]; cin >> n >> abc[] >> abc[] >> abc[];
for(int i = ; i <= n; i++) dp[i] = -; //dp[0] 初始化为 0, 其他初始化为负无穷
for(int i = ; i < ; i++) for(int j = abc[i]; j <= n; j++) dp[j] = max(dp[j], dp[j - abc[i]] + );
cout << dp[n] << endl;
return ;
}
Codeforces 189A. Cut Ribbon的更多相关文章
- 【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 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 : ...
- CodeForces 189A 166E 【DP ·水】
非常感谢 Potaty 大大的援助使得我最后A出了这两题DP ================================== 189A : 求切分后的ribbon最多的数目,不过要求切分后只能存 ...
- Cut Ribbon
Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the follo ...
- [CF189A]Cut Ribbon(完全背包,DP)
题目链接:http://codeforces.com/problemset/problem/189/A 题意:给你长为n的绳子,每次只允许切a,b,c三种长度的段,问最多能切多少段.注意每一段都得是a ...
- Codeforces --- 982C Cut 'em all! DFS加贪心
题目链接: https://cn.vjudge.net/problem/1576783/origin 输入输出: ExamplesinputCopy42 44 13 1outputCopy1input ...
随机推荐
- perl的Sys::Syslog模块(openlog,syslog,closelog函数,setlogsock)-自定义日志
perl的Sys::Syslog模块(openlog,syslog,closelog函数,setlogsock)-自定义日志 http://blog.chinaunix.net/xmlrpc.php? ...
- [洛谷P3521][POI2011]ROT-Tree Rotations
题目大意:给一棵$n(n\leqslant2\times10^5)$个叶子的二叉树,可以交换每个点的左右子树,要求前序遍历叶子的逆序对最少.输出最少的逆序对个数 题解:线段树合并,对于每个节点求出交换 ...
- [Leetcode] Path Sum路径和
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- 【BZOJ 4007】[JLOI2015]战争调度 DP+搜索+状压
又是一道思路清新的小清晰. 观察题目,如果我们确定了平民或者贵族的任意一方,我们便可以贪心的求出另一方,至此20分:我们发现层数十分小,那么我们就也是状压层数,用lca转移,线性dp,至此50分(好像 ...
- Reasons to use innodb_file_per_table
When working with InnoDB, you have two ways for managing the tablespace storage: Throw everything in ...
- TCP之close_wait
TCP之close_wait 浏览:3697次 出处信息 /* * @author: ahuaxuan * @date: 2010-4-30 */ 查看各状态连接数: netstat -n | aw ...
- Ubuntu1604 install netease-cloud music
Two issue: 1. There is no voice on my computer, and the system was mute and cannot unmute. eric@E641 ...
- Eclipse工具栏太多,自定义工具栏,去掉调试
Window --> Customize Perspective... --> Tool Bar Visibility 去掉勾选debug Tip:最新版本Customize Persp ...
- 在Servlet中出现一个输出中文乱码的问题
添加:reqeust.setCharacterEncoding("utf-8");
- Nodejs写的搬家工具知识分享
这篇文章 主要学习这两个模块的使用: request-promise-native : https://github.com/request/request-promise-native cheeri ...