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…
B. Word Cut   Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split oper…
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…
[BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权值为i的二叉树的个数. 两棵树不同当且仅当树的形态不一样或者是树的某个点的点权不一样 分析 设\(c(i)\)表示数值i是否在集合中.\(f(i)\)表示权值为i的二叉树的个数.那么 \[f(n)=\sum_{i=1}^n c(i) \sum_{j=0}^{n-i} f(j)f(n-i-j)\] 其…
题目链接: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]] !=…
Word Cut 题目连接: http://codeforces.com/problemset/problem/176/C Description Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word in…
Word Cut Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 176B Description Let's consider one interesting word game. In this game you should transform one word into another through specia…
题目链接: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…
题目链接:http://codeforces.com/problemset/problem/189/A 题意: 给你一个长度为 N 的布条, 再给你三个长度 a, b , c.你可以用剪刀去剪这些布条, 但是每次剪完后, 布条的长度必须是 a 或者 b 或者 c, 问按照这个规则, 最多可以把这个布条剪成几段. 思路: 上述问题可以换一种说法, 这里有无线个长度为 a, b, c的布条, 让你选择最多的个数, 使得其连接起来长度恰好为 N.这很显然是根基础的完全背包的拓展问题.所以只解套用模板就…