随笔分类 -  DP

摘要: P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京。他使用自己的压缩器进行压 缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中。P教授有编号为1...N的N件玩具,第i件玩具经过 压缩后变成一维长度为Ci.为了方便整理,P教授要求在一个一维容器中的玩具编号是连续的。同时如果一个一维容 器中有多个玩具,那么两件玩具之间要加入一个单位长度的填充物,形式地说如果将第i件玩具到第j个玩具放到一 个容器中,那么容器的长度将为 x=j-i+Sigma(Ck) i<=K<=j 制作容器的费用与容器的长度有关,根据教授研究, 如果容器长度为x,其制作费用为(X-L)^2.其中L是一个常量。P教授不关心容器的数目,他可以制作出 阅读全文
posted @ 2017-01-14 16:35 ZegWe 阅读(232) 评论(0) 推荐(0)
摘要: Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of his paper was filled with squares and rectangles), he dreamt of filling a large rectangle with small rectangles of width 2 and height 1 in var 阅读全文
posted @ 2016-11-02 22:04 ZegWe 阅读(191) 评论(0) 推荐(0)
摘要:A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers. Write a program to find and print the nth element in this sequence. 阅读全文
posted @ 2016-11-02 18:11 ZegWe 阅读(415) 评论(0) 推荐(0)
摘要: 给定一棵树,每个节点有一个值。对于一条路径,它的值为路径上所有点的值的乘积。求出树上所有路径的值的和。 注意:单个点也算一条路径。 阅读全文
posted @ 2016-10-30 15:11 ZegWe 阅读(151) 评论(0) 推荐(0)
摘要:Given an integer sequence { an } of length N, you are to cut the sequence into several parts every one of which is a consecutive subsequence of the original sequence. Every part must satisfy that the sum of the integers in the part is not greater than a given integer M. You are to find a cutting that minimizes the su 阅读全文
posted @ 2016-10-25 22:03 ZegWe 阅读(964) 评论(0) 推荐(1)
摘要:These days, Sempr is crazed on one problem named Crazy Thair. Given N (1 ≤ N ≤ 50000) numbers, which are no more than 109, Crazy Thair is a group of 5 numbers {i, j, k, l, m} satisfying: 1. 1 ≤ i < j < k < l < m ≤ N 2. Ai < Aj < A 阅读全文
posted @ 2016-10-24 18:29 ZegWe 阅读(241) 评论(0) 推荐(0)
摘要:对于一个排列,考虑相邻的两个元素,如果后面一个比前面一个大,表示这个位置是上升的,用 I 表示,反之这个位置是下降的,用 D表示。如排列 3,1,2,7,4,6,5 可以表示为 DIIDID。 现在给出一个长度为 n-1的排列表示,问有多少种 1 到n 的排列满足这种表示。 阅读全文
posted @ 2016-10-22 11:16 ZegWe 阅读(623) 评论(3) 推荐(2)
摘要:There are n students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the i-th student ai minutes to finish his/her independent piece. 阅读全文
posted @ 2016-10-12 14:59 ZegWe 阅读(304) 评论(0) 推荐(0)