您的位置:首页 > 运维架构

poj 1157 LITTLE SHOP OF FLOWERS

2013-06-18 11:30 253 查看
LITTLESHOPOFFLOWERS

TimeLimit:1000MSMemoryLimit:10000K
TotalSubmissions:15958Accepted:7398
Description
Youwanttoarrangethewindowofyourflowershopinamostpleasantway.YouhaveFbunchesofflowers,eachbeingofadifferentkind,andatleastasmanyvasesorderedinarow.Thevasesaregluedontotheshelfandarenumbered
consecutively1throughV,whereVisthenumberofvases,fromlefttorightsothatthevase1istheleftmost,andthevaseVistherightmostvase.Thebunchesaremoveableandareuniquelyidentifiedbyintegersbetween1andF.Theseid-numbershave
asignificance:Theydeterminetherequiredorderofappearanceoftheflowerbunchesintherowofvasessothatthebunchimustbeinavasetotheleftofthevasecontainingbunchjwheneveri<j.Suppose,forexample,youhavebunchofazaleas(id-number=1),
abunchofbegonias(id-number=2)andabunchofcarnations(id-number=3).Now,allthebunchesmustbeputintothevaseskeepingtheirid-numbersinorder.Thebunchofazaleasmustbeinavasetotheleftofbegonias,andthebunchofbegoniasmustbe
inavasetotheleftofcarnations.Iftherearemorevasesthanbunchesofflowersthentheexcesswillbeleftempty.Avasecanholdonlyonebunchofflowers.

Eachvasehasadistinctcharacteristic(justlikeflowersdo).Hence,puttingabunchofflowersinavaseresultsinacertainaestheticvalue,expressedbyaninteger.Theaestheticvaluesarepresentedinatableasshownbelow.Leavingavaseemptyhas
anaestheticvalueof0.

VASES
1
2
3
4
5
Bunches
1(azaleas)
723-5-2416
2(begonias)
521-41023
3(carnations)
-21
5-4-2020
Accordingtothetable,azaleas,forexample,wouldlookgreatinvase2,buttheywouldlookawfulinvase4.

Toachievethemostpleasanteffectyouhavetomaximizethesumofaestheticvaluesforthearrangementwhilekeepingtherequiredorderingoftheflowers.Ifmorethanonearrangementhasthemaximalsumvalue,anyoneofthemwillbeacceptable.Youhave
toproduceexactlyonearrangement.

Input

Thefirstlinecontainstwonumbers:F,V.
ThefollowingFlines:EachoftheselinescontainsVintegers,sothatAijisgivenasthe
jthnumberonthe(i+1)stlineoftheinputfile.

1<=F<=100whereFisthenumberofthebunchesofflowers.Thebunchesarenumbered1throughF.

F<=V<=100whereVisthenumberofvases.

-50<=Aij<=50whereAijistheaestheticvalueobtainedbyputtingtheflowerbunchiintothevasej.

Output
Thefirstlinewillcontainthesumofaestheticvaluesforyourarrangement.
SampleInput
35
723-5-2416
521-41023
-215-4-2020

SampleOutput
53


题意:有F种花,编号为1—F,V种花瓶,编号为1—V,当一种花插进一个编号为v1的花瓶时,比这种花编号大的花只能插进编号>v1的花瓶,每种花插进每种花瓶都有一个美术价值,要求使得全部花美术价值的总和最大。

思路:简单DP,设d[i][j]表示插到第i朵花,且第i朵花插进第j个花瓶时的最大美术价值。


AC代码:

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<vector>
#include<cstdlib>

usingnamespacestd;

intmain()
{
intf,v;
intmap[105][105];
intdp[105][105];
while(cin>>f>>v)
{
for(inti=0;i<f;i++)
for(intj=0;j<v;j++)
cin>>map[i][j];

for(inti=0;i<f;i++)
for(intj=0;j<v;j++)
dp[i][j]=-100000000;

for(intj=0;j<v;j++)
dp[0][j]=map[0][j];

for(inti=1;i<f;i++)
for(intj=0;j<v;j++)
for(intk=0;k<j;k++)
dp[i][j]=max(dp[i][j],dp[i-1][k]+map[i][j]);

intmax=-100000000;
for(intj=0;j<v;j++)
if(dp[f-1][j]>max)
max=dp[f-1][j];
cout<<max<<endl;
}
return0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: