POJ 1874Trade on Verweggistan
来源:互联网 发布:软件培训大纲 编辑:程序博客网 时间:2024/05/02 00:22
Trade on Verweggistan
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 1238 Accepted: 355
Description
Since the days of Peter Stuyvesant and Abel Tasman, Dutch merchants have been traveling all over the world to buy and sell goods. Once there was some trade on Verweggistan, but it ended after a short time. After reading this story you will understand why.
At that time Verweggistan was quite popular, because it was the only place in the world where people knew how to make a 'prul'. The end of the trade on Verweggistan meant the end of the trade in pruls (or 'prullen', as the Dutch plural said), and very few people nowadays know what a prul actually is.
Pruls were manufactured in workyards. Whenever a prul was finished it was packed in a box, which was then placed on top of the pile of previously produced pruls. On the side of each box the price was written. The price depended on the time it took to manufacture the prul. If all went well, a prul would cost one or two florins, but on a bad day the price could easily rise to 15 florins or more. This had nothing to do with quality; all pruls had the same value.
In those days pruls sold for 10 florins each in Holland. Transportation costs were negligible since the pruls were taken as extra on ships that would sail anyway. When a Dutch merchant went to Verweggistan, he had a clear purpose: buy pruls, sell them in Holland, and maximize his profits. Unfortunately, the Verweggistan way of trading pruls made this more complicated than one would think.
One would expect that merchants would simply buy the cheapest pruls, and the pruls that cost more than 10 florins would remain unsold. Unfortunately, all workyards on Verweggistan sold their pruls in a particular order. The box on top of the pile was sold first, then the second one from the top, and so on. So even if the fifth box from the top was the cheapest one, a merchant would have to buy the other four boxes above to obtain it.
As you can imagine, this made it quite difficult for the merchants to maximize their profits by buying the right set of pruls. Not having computers to help with optimization, they quickly lost interest in trading pruls at all.
In this problem, you are given the description of several workyard piles. You have to calculate the maximum profit a merchant can obtain by buying pruls from the piles according to the restrictions given above. In addition, you have to determine the number of pruls he has to buy to achieve this profit.
At that time Verweggistan was quite popular, because it was the only place in the world where people knew how to make a 'prul'. The end of the trade on Verweggistan meant the end of the trade in pruls (or 'prullen', as the Dutch plural said), and very few people nowadays know what a prul actually is.
Pruls were manufactured in workyards. Whenever a prul was finished it was packed in a box, which was then placed on top of the pile of previously produced pruls. On the side of each box the price was written. The price depended on the time it took to manufacture the prul. If all went well, a prul would cost one or two florins, but on a bad day the price could easily rise to 15 florins or more. This had nothing to do with quality; all pruls had the same value.
In those days pruls sold for 10 florins each in Holland. Transportation costs were negligible since the pruls were taken as extra on ships that would sail anyway. When a Dutch merchant went to Verweggistan, he had a clear purpose: buy pruls, sell them in Holland, and maximize his profits. Unfortunately, the Verweggistan way of trading pruls made this more complicated than one would think.
One would expect that merchants would simply buy the cheapest pruls, and the pruls that cost more than 10 florins would remain unsold. Unfortunately, all workyards on Verweggistan sold their pruls in a particular order. The box on top of the pile was sold first, then the second one from the top, and so on. So even if the fifth box from the top was the cheapest one, a merchant would have to buy the other four boxes above to obtain it.
As you can imagine, this made it quite difficult for the merchants to maximize their profits by buying the right set of pruls. Not having computers to help with optimization, they quickly lost interest in trading pruls at all.
In this problem, you are given the description of several workyard piles. You have to calculate the maximum profit a merchant can obtain by buying pruls from the piles according to the restrictions given above. In addition, you have to determine the number of pruls he has to buy to achieve this profit.
Input
The input describes several test cases. The first line of input for each test case contains a single integer w, the number of workyards in the test case (1 <= w <= 50).
This is followed by w lines, each describing a pile of pruls. The first number in each line is the number b of boxes in the pile (0 <= b <= 20). Following it are b positive integers, indicating the prices (in florins) of the pruls in the stack, given from top to bottom.
The input is terminated by a description starting with w = 0. This description should not be processed.
This is followed by w lines, each describing a pile of pruls. The first number in each line is the number b of boxes in the pile (0 <= b <= 20). Following it are b positive integers, indicating the prices (in florins) of the pruls in the stack, given from top to bottom.
The input is terminated by a description starting with w = 0. This description should not be processed.
Output
For each test case, print the case number (1, 2, ...). Then print two lines, the first containing the maximum profit the merchant can achieve. The second line should specify the number of pruls the merchant has to buy to obtain this profit. If this number is not uniquely determined, print the possible values in increasing order. If there are more than ten possible values, print only the 10 smallest.
Display a blank line between test cases.
Display a blank line between test cases.
Sample Input
16 12 3 10 7 16 525 7 3 11 9 109 1 2 3 4 10 16 10 4 160
Sample Output
Workyards 1Maximum profit is 8.Number of pruls to buy: 4Workyards 2Maximum profit is 40.Number of pruls to buy: 6 7 8 9 10 12 13
Source
World Finals 1999
/*
背包问题的应用,依次处理每个yard然后寻找达到最大值的可行方案数,
然后往前背包即可
*/
- POJ 1874Trade on Verweggistan
- poj 1874 Trade on Verweggistan
- UVA - 812 Trade on Verweggistan
- UVA812-Trade on Verweggistan(暴力)
- uva 812 - Trade on Verweggistan(暴力)
- 812 - Trade on Verweggistan (暴力枚举)
- UVa 812 - Trade on Verweggistan(贪心)
- UVa 812 - Trade on Verweggistan 解题报告(枚举)
- UVA - 812 Trade on Verweggistan dfs + 贪心
- UVa 812 - Trade on Verweggistan (贪心+dfs)
- p1874_Trade on Verweggistan
- Pressure Builds on Chinese Trade Deficit
- trade
- Trade
- Distance on Chessboard POJ
- Play on Words POJ
- Swedish Apparel Giant: EU' Restriction on Chinese Textile Hurts Free Trade Philosophy
- World trade is on the mend, but the strength of the rebound remains uncertain
- ARM嵌入式主板之路
- 屏幕打印的小程序
- linux 命令大集
- 图片上传和显示控件
- HP发布了针对QTP 10的Web2.0 Feature Pack
- POJ 1874Trade on Verweggistan
- 背完这444句,你的口语就无敌了
- 一定有你喜欢的一句话
- (转) 高性能服务器设计
- SCI论文从入门到精通
- 妄论金山词霸之发展
- VS2005/2008中清除最近打开项目的方法如何被推荐?
- Symbian环境配置
- Symbian 资源 网址