Codeforces 189A. Cut Ribbon】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/189/A 题意: 给你一个长度为 N 的布条, 再给你三个长度 a, b , c.你可以用剪刀去剪这些布条, 但是每次剪完后, 布条的长度必须是 a 或者 b 或者 c, 问按照这个规则, 最多可以把这个布条剪成几段. 思路: 上述问题可以换一种说法, 这里有无线个长度为 a, b, c的布条, 让你选择最多的个数, 使得其连接起来长度恰好为 N.这很显然是根基础的完全背包的拓展问题.所以只解套用模板就…
题目链接:http://codeforces.com/problemset/problem/189/A 题意:一个长度为n的纸带,允许切割若干次,每次切下的长度只能是{a, b, c}之一.问最多能切成多少块. 思路:动态规划,记dp[i] 为当前已经切下总长度 i 时最多能切成的块数,即规模为 i 的子问题. 状态的转移比较好想,每次只可能从dp[i-a], dp[i-b], dp[i-c]三个方向通过加一转移过来. 问题的初始化我考虑得有点复杂:先把a, b, c从小到大排序,然后对于 i…
#include<bits/stdc++.h> using namespace std; const int maxn = 4000 + 131; int n, a, b, c; int Dp[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> a >> b >> c; memset(Dp,0,sizeof(Dp)); Dp[a] = Dp[b] = D…
Cut Ribbon time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output 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…
A. Cut Ribbon time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions: After…
time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : standard output Polycarpus has a ribbon, its length is nnn. He wants to cut the ribbon in a way that fulfils the following two conditions: After the…
非常感谢 Potaty 大大的援助使得我最后A出了这两题DP ================================== 189A : 求切分后的ribbon最多的数目,不过要求切分后只能存在a or b or c 的长度 O(n)的效率:遍历下来求 f[i - a].f[i - b]. f[i - c] 中的最大值 如果i - a || b || c 的值小于0那么跳过 来一张图,过程非常清晰 当然,初始化对f 数组置-INF,否则可能出错 //#pragma comment(lin…
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…
题目链接:http://codeforces.com/problemset/problem/189/A 题意:给你长为n的绳子,每次只允许切a,b,c三种长度的段,问最多能切多少段.注意每一段都得是a,b,c中长度的一种. 解法:这个题可以看作是完全背包,但是由于切割长度有限制,所以要做一些调整.我们初始化dp(i)为长度为i时的最优解.一开始dp(a)=dp(b)=dp(c)=1是显而易见的,我们转移的起点也是这里.我们不希望枚举到不符合条件的情况,所以多一步判断:dp[j-w[i]] !=…
题目链接: https://cn.vjudge.net/problem/1576783/origin 输入输出: ExamplesinputCopy42 44 13 1outputCopy1inputCopy31 21 3outputCopy-1inputCopy107 18 48 104 76 59 33 52 102 5outputCopy4inputCopy21 2outputCopy0NoteIn the first example you can remove the edge bet…