2714 - 橱窗布置

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB

假设你想以最美观的方式布置花店的橱窗。现在你有F束不同品种的花束,同时你也有至少同样数量的花瓶被按顺序摆成一行。这些花瓶的位置固定于架子上,并从1至V顺序编号,V是花瓶的数目,从左至右排列,则最左边的是花瓶1,最右边的是花瓶V。花束可以移动,并且每束花用1至F间的整数唯一标识。标识花束的整数决定了花束在花瓶中的顺序,如果I<J,则令花束I必须放在花束J左边的花瓶中。

  例如,假设一束杜鹃花的标识数为1,一束秋海棠的标识数为2,一束康乃馨的标识数为3,所有的花束在放入花瓶时必须保持其标识数的顺序,即:杜鹃花必须放在秋海棠左边的花瓶中,秋海棠必须放在康乃馨左边的花瓶中。如果花瓶的数目大于花束的数目。则多余的花瓶必须空置,且每个花瓶中只能放一束花。
  每一个花瓶都具有各自的特点。因此,当各个花瓶中放入不同的花束时,会产生不同的美学效果,并以美学值(一个整数)来表示,空置花瓶的美学值为零。
  在上述例子中,花瓶与花束的不同搭配所具有的美学值,如下表所示。
<tbody>
	<tr>
		<td valign="top" width="101" style="border:0.5pt solid #000000;">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">花</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">瓶1</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">瓶2</span><span style="font-size:10.5pt;font-family:'Times New Roman';line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">瓶3</span><span style="font-size:10.5pt;font-family:'Times New Roman';line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">瓶4</span><span style="font-size:10.5pt;font-family:'Times New Roman';line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">瓶5</span><span style="font-size:10.5pt;font-family:'Times New Roman';line-height:normal !important;"></span> 
			</p>
		</td>
	</tr>
	<tr>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">花&nbsp;1&nbsp;(杜鹃花)</span><span style="font-size:10.5pt;font-family:'Times New Roman';line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">7</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;background-color:#FFFF00;">23</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">-5</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">-24</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">16</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
	</tr>
	<tr>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">花&nbsp;2&nbsp;(秋海棠)</span><span style="font-size:10.5pt;font-family:'Times New Roman';line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">5</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">21</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">-4</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;background-color:#FFFF00;">10</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">23</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
	</tr>
	<tr>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">花&nbsp;3&nbsp;(康乃馨)</span><span style="font-size:10.5pt;font-family:'Times New Roman';line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">-21</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">5</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">-4</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">-20</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
		<td valign="top" width="101">
			<p class="0" style="text-align:justify;">
				<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;background-color:#FFFF00;">20</span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span> 
			</p>
		</td>
	</tr>
</tbody>

<span style="font-size:10.5pt;font-family:'Times New Roman';line-height:normal !important;"></span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"> 例如,根据上表,杜鹃花放在花瓶2中,会显得非常好看;但若放在花瓶4中则显得十分难看。</span><span style="font-size:10.5pt;font-family:'Times New Roman';line-height:normal !important;"><br />

    为取得最佳美学效果,你必须在保持花束顺序的前提下,使花束的摆放取得最大的美学值。如果有不止一种的摆放方式具有最大的美学值,则其中任何一直摆放方式都可以接受,但你只要输出任意一种摆放方式。

<span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;"></span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">(2)假设条件</span><span style="font-size:10.5pt;font-family:'Times New Roman';line-height:normal !important;"></span> 

<span style="font-size:10.5pt;font-family:'Times New Roman';line-height:normal !important;"></span><span style="font-size:10.5pt;font-family:宋体;line-height:normal !important;">1≤F≤100,其中F为花束的数量,花束编号从1至F。</span><span style="font-size:10.5pt;font-family:'Times New Roman';line-height:normal !important;"><br />

F≤V≤100,其中V是花瓶的数量。
-50≤Aij≤50,其中Aij是花束i在花瓶j中的美学值。

题目输入

输入文件是正文文件(text file),文件名是flower.inp
第一行包含两个数:F,V。
随后的F行中,每行包含V个整数,Aij 即为输入文件中第(i+1 )行中的第j个数。

题目输出

输出文件必须是名为flower.out的正文文件,文件应包含两行:
  
第一行是程序所产生摆放方式的美学值。
    
第二行必须用F个数表示摆放方式,即该行的第K个数表示花束K所在的花瓶的编号。

输入/输出样例

输入格式

3 5
7 23 -5 -24 16
5 21 -4 10 23
-21 5 -4 -20 20

输出格式

53
2 4 5

C++解答

#include<cstdio>
#include<cstring>
using namespace std;
int a[201][201],b[201][201];
int INF=1000000000;
int max(int a,int b)
{
	if(a>b)
	{
		return a;
	}
	return b;
}
int Print(int i,int j)
{
	int n;
	if(i>0)
	{
		n=i;
		while(b[i][n]!=j)
		{
			n++;
		}
		Print(i-1,j-a[i][n]);
		printf("%d ",n);
	}
}
int main()
{
    int F,V;
    while(~scanf("%d%d",&F,&V))
    {
        for(int i=1;i<=F;i++)
            for(int j=1;j<=V;j++)
                scanf("%d",&a[i][j]);
        for(int i=1;i<=F;i++)
            for(int j=0;j<=V;j++)
                b[i][j] = -INF;
        for(int i=1;i<=F;i++)
        {
            for(int j=i;j<=V;j++)
            {
                if(b[i-1][j-1] + a[i][j] <= b[i][j-1])
                    b[i][j] = b[i][j-1];
                else
                {
                    b[i][j] = b[i-1][j-1] + a[i][j];
                }
            }
        }
        printf("%d\n",b[F][V]);
        Print(F,b[F][V]);
        puts("");
    }
    return 0;
}