Farmer Brown's cows are up in arms, having heard that McDonalds is
considering the introduction of a new product: Beef McNuggets. The
cows are trying to find any possible way to put such a product in a
negative light.
One strategy the cows are pursuing is that of `inferior packaging'.
``Look,'' say the cows, ``if you have Beef McNuggets in boxes of 3, 6,
and 10, you can not satisfy a customer who wants 1, 2, 4, 5, 7, 8, 11,
14, or 17 McNuggets. Bad packaging: bad product.''
Help the cows. Given N (the number of packaging options, 1 <= N
<= 10), and a set of N positive integers (1 <= i <= 256) that
represent the number of nuggets in the various packages, output the
largest number of nuggets that can not be purchased by buying nuggets
in the given sizes. Print 0 if all possible purchases can be made or
if there is no bound to the largest number.
The largest impossible number (if it exists) will be no larger than
2,000,000,000.
PROGRAM NAME: nuggets
INPUT FORMAT
Line 1:
N, the number of packaging options
Line 2..N+1:
The number of nuggets in one kind of
box
SAMPLE INPUT (file nuggets.in)
3 3 6 10
OUTPUT FORMAT
The output file should contain a single line containing a single integer
that represents the largest number of nuggets that can not be represented
or 0 if all possible purchases can be made or if there is no bound to
the largest number.
]]>USACO 3.3 Home on the Rangehttp://www.shnenglu.com/yuziyu/archive/2009/07/08/89557.htmlYZYYZYWed, 08 Jul 2009 09:44:00 GMThttp://www.shnenglu.com/yuziyu/archive/2009/07/08/89557.htmlhttp://www.shnenglu.com/yuziyu/comments/89557.htmlhttp://www.shnenglu.com/yuziyu/archive/2009/07/08/89557.html#Feedback0http://www.shnenglu.com/yuziyu/comments/commentRss/89557.htmlhttp://www.shnenglu.com/yuziyu/services/trackbacks/89557.html濡傛灉dp[i][j][m]瀹屾暣錛屽垯褰撲笖浠呭綋dp[i][j][m-1],dp[i+1][j][m-1],dp[i][j+1][m-1],dp[i+1][j+1][m-1]鐨勬鏂瑰艦涔熸槸瀹屾暣鐨?鐢諱釜鍥懼氨寰堟竻鏅頒簡)銆傜敱浜庢垜浠粠涓婂埌涓嬶紝浠庡乏鍒板彸鎵弿姣忎釜鐐癸紝鍦ㄦ瘡涓杞甶,j鐢ㄨ繃涓嬈★紝灝變笉浼氬啀浣跨敤錛屾墍浠ュ彧闇鐢ㄤ簩緇存暟緇勪繚瀛榙p[i][j]錛屽嵆鍙?br />鏃墮棿澶嶆潅搴︿負O(n^3),絀洪棿澶嶆潅搴︿負O(n^2)銆俛nalysis涓湁涓椂闂村鏉傚害涓篛(n^2),絀洪棿O(n)鐨勮В娉曘?br />