poj 1157 LITTLE SHOP OF FLOWERS
2013-06-18 11:30
253 查看
LITTLESHOPOFFLOWERS
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.
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
SampleOutput
TimeLimit:1000MS | MemoryLimit:10000K | |
TotalSubmissions:15958 | Accepted:7398 |
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) | 7 | 23 | -5 | -24 | 16 |
2(begonias) | 5 | 21 | -4 | 10 | 23 | |
3(carnations) | -21 | 5 | -4 | -20 | 20 |
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;
}
相关文章推荐
- POJ-1157-LITTLE SHOP OF FLOWERS
- POJ - 1157 LITTLE SHOP OF FLOWERS
- POJ 1157 LITTLE SHOP OF FLOWERS
- POJ 1157 LITTLE SHOP OF FLOWERS(动态规划)
- POJ 1157 LITTLE SHOP OF FLOWERS(坐标类DP)
- poj1157 LITTLE SHOP OF FLOWERS
- POJ 1157 LITTLE SHOP OF FLOWERS
- POJ 1157 - LITTLE SHOP OF FLOWERS (动态规划)
- poj 1157 LITTLE SHOP OF FLOWERS
- poj 动态规划DP - 1157 LITTLE SHOP OF FLOWERS
- POJ 1157 LITTLE SHOP OF FLOWERS(前i朵花放到前j个花瓶)
- POJ 1157 LITTLE SHOP OF FLOWERS
- 【DP】POJ-1157 LITTLE SHOP OF FLOWERS
- poj 1157 LITTLE SHOP OF FLOWERS(DP)
- POJ1157_LITTLE SHOP OF FLOWERS_DP
- poj1157 LITTLE SHOP OF FLOWERS(dp)
- poj 1157 LITTLE SHOP OF FLOWERS
- POJ 1157 LITTLE SHOP OF FLOWERS(DP)
- POJ 1157 LITTLE SHOP OF FLOWERS
- POJ 1157 Little shop of flowers(DP,最优搭配)