青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

SGU 104. Little shop of flowers

104. Little shop of flowers

time limit per test: 0.50 sec.
memory limit per test: 4096 KB

PROBLEM

You want to arrange the window of your flower shop in a most pleasant way. You have F bunches of flowers, each being of a different kind, and at least as many vases ordered in a row. The vases are glued onto the shelf and are numbered consecutively 1 through V, where V is the number of vases, from left to right so that the vase 1 is the leftmost, and the vase V is the rightmost vase. The bunches are moveable and are uniquely identified by integers between 1 and F. These id-numbers have a significance: They determine the required order of appearance of the flower bunches in the row of vases so that the bunch i must be in a vase to the left of the vase containing bunch j whenever i < j. Suppose, for example, you have bunch of azaleas (id-number=1), a bunch of begonias (id-number=2) and a bunch of carnations (id-number=3). Now, all the bunches must be put into the vases keeping their id-numbers in order. The bunch of azaleas must be in a vase to the left of begonias, and the bunch of begonias must be in a vase to the left of carnations. If there are more vases than bunches of flowers then the excess will be left empty. A vase can hold only one bunch of flowers.

Each vase has a distinct characteristic (just like flowers do). Hence, putting a bunch of flowers in a vase results in a certain aesthetic value, expressed by an integer. The aesthetic values are presented in a table as shown below. Leaving a vase empty has an aesthetic value of 0.

   

V A S E S

   

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

 

According to the table, azaleas, for example, would look great in vase 2, but they would look awful in vase 4.

To achieve the most pleasant effect you have to maximize the sum of aesthetic values for the arrangement while keeping the required ordering of the flowers. If more than one arrangement has the maximal sum value, any one of them will be acceptable. You have to produce exactly one arrangement.

ASSUMPTIONS

  • 1 ≤ F ≤ 100 where F is the number of the bunches of flowers. The bunches are numbered 1 through F.

     

  • FV ≤ 100 where V is the number of vases.

     

  • -50 £ Aij £ 50 where Aij is the aesthetic value obtained by putting the flower bunch i into the vase j.

     

 

Input

  • The first line contains two numbers: F, V.

     

  • The following F lines: Each of these lines contains V integers, so that Aij is given as the j’th number on the (i+1)’st line of the input file.

     

 

Output

  • The first line will contain the sum of aesthetic values for your arrangement.

     

  • The second line must present the arrangement as a list of F numbers, so that the k’th number on this line identifies the vase in which the bunch k is put.

     

 

Sample Input

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

Sample Output

53
            2 4 5
            
Analysis

It is called a problem derived from IOI. As a typical DP problem, the only thing we need to think about is the dynamic function. This problem is harder since we need to record the tracy of dynamic programing.
Let's assume that dp[i][j] means the maximum sum of  aesthetic values about first i flowers puts in first j vases. Then, since the only choice for the ith flower is whether put or not, the function is obvious: dp[i][j]=max{dp[i][j-1],dp[i-1][j-1]+a[i][j]}. Limitness is that i<j should be held and record the action "put".

Code
#include <stdio.h>
#include 
<stdlib.h>
#include 
<string.h>
#define max(a,b) a>b?a:b

int dp[101][101];
bool put[101][101];
int f,v;
int a[101][101];    

void putprint(int i,int j){
    
while (put[i][j]) j--;
    
if (i>1) putprint(i-1,j-1);
    
if (i==f) printf("%d\n",j);
    
else printf("%d ",j);
}


int main(){
    
int i,j;
    
    scanf(
"%d %d",&f,&v);
    
for (i=1;i<=f;i++)
        
for (j=1;j<=v;j++)
            scanf(
"%d",&a[i][j]);
    
    memset(dp,
0,sizeof dp);
    
for (i=1;i<=f;i++)
        
for (j=1;j<=v-f+i;j++){
            dp[i][i
-1]=-32767;
            dp[i][j]
=dp[i-1][j-1]+a[i][j];;put[i][j]=false;
            
if (dp[i][j-1]>(dp[i-1][j-1]+a[i][j])){
                dp[i][j]
=dp[i][j-1];
                put[i][j]
=true;
            }
                
        }

    printf(
"%d\n",dp[f][v]);
    putprint(f,v);
    
return 0;
}

posted on 2008-11-03 14:35 幻浪天空領主 閱讀(1047) 評論(1)  編輯 收藏 引用 所屬分類: SGU

評論

# re: SGU 104. Little shop of flowers 2011-06-07 11:14 zqynux

dp[i][i-1]=-32767;
這句話為什么可以解決負數的問題??  回復  更多評論   


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


<2011年6月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

導航

統計

常用鏈接

留言簿(1)

隨筆檔案(2)

文章分類(23)

文章檔案(22)

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            久久国产精品99久久久久久老狼| 久久国产夜色精品鲁鲁99| 久久久久99精品国产片| 国产日产高清欧美一区二区三区| 午夜精品国产| 午夜免费久久久久| 国产日韩欧美中文| 久久网站热最新地址| 久久精品导航| 亚洲欧洲精品一区二区三区不卡 | av不卡在线| 一区二区动漫| 国产亚洲欧美日韩日本| 免费美女久久99| 欧美精品一区三区在线观看| 在线视频精品| 久久国产精品一区二区| 亚洲大胆av| 99国内精品久久| 国产亚洲精品综合一区91| 你懂的网址国产 欧美| 欧美欧美在线| 久久99在线观看| 麻豆精品视频在线观看| 在线性视频日韩欧美| 校园春色国产精品| 亚洲伦理精品| 欧美制服丝袜第一页| 亚洲精品国产视频| 亚洲综合电影| 日韩视频永久免费观看| 亚洲影院免费观看| 性欧美1819性猛交| 亚洲精品久久久久中文字幕欢迎你| 亚洲精品系列| 极品少妇一区二区三区| 99在线|亚洲一区二区| 激情欧美日韩| 亚洲免费视频观看| av成人黄色| 美国十次了思思久久精品导航| 亚洲欧美综合国产精品一区| 久久久久久穴| 欧美在线关看| 国产精品高清一区二区三区| 欧美国产大片| 136国产福利精品导航网址| 亚洲一区www| 亚洲色图综合久久| 欧美国产一区视频在线观看| 久久综合色88| 国产精品丝袜91| 一二美女精品欧洲| 日韩小视频在线观看| 久久亚洲春色中文字幕| 久久免费的精品国产v∧| 国产精品入口| 亚洲一二区在线| 亚洲视屏一区| 欧美日韩三级在线| 亚洲欧洲日本一区二区三区| 在线日韩欧美| 浪潮色综合久久天堂| 麻豆精品在线视频| 国产综合在线视频| 香港久久久电影| 久久精品日产第一区二区| 国产精品进线69影院| 一区二区三区四区蜜桃| 一区二区三区产品免费精品久久75| 欧美黄色影院| 亚洲精品一区二区三区四区高清 | 欧美福利视频一区| 欧美韩日高清| 亚洲欧洲一区二区三区在线观看| 免费成人网www| 亚洲精品欧美精品| 亚洲美女精品成人在线视频| 欧美电影资源| 一本久久青青| 久久国内精品视频| 国产综合自拍| 欧美成人精品不卡视频在线观看| 免费高清在线视频一区·| 亚洲国产精品va在线看黑人| 欧美风情在线观看| 中文一区二区在线观看| 久久国产欧美| 亚洲精品免费一区二区三区| 欧美日本国产在线| 亚洲免费在线视频一区 二区| 久久精品国产一区二区三| 一区二区三区无毛| 欧美大片在线看| 亚洲小说春色综合另类电影| 久久av一区二区| 亚洲国产视频一区二区| 欧美精品一区二区三区蜜臀| 亚洲一区二区三区精品在线观看 | 亚洲高清自拍| 国产精品高潮视频| 欧美在线播放高清精品| 欧美电影资源| 亚洲欧美一级二级三级| 狠狠色狠狠色综合日日91app| 一本色道**综合亚洲精品蜜桃冫 | 欧美一区二区大片| 亚洲国产精品一区制服丝袜| 欧美日本高清视频| 久久久久久久久伊人| 夜久久久久久| 欧美激情中文不卡| 香港成人在线视频| 日韩一级片网址| 国内精品美女在线观看| 欧美日本亚洲| 久久久久免费视频| 亚洲一区二区久久| 亚洲品质自拍| 牛牛影视久久网| 久久精品三级| 亚洲欧美日韩成人| 99爱精品视频| 亚洲国产你懂的| 国产午夜精品理论片a级探花| 欧美日韩亚洲国产一区| 久久久久国产精品一区二区| 亚洲制服av| 亚洲小说春色综合另类电影| 亚洲青涩在线| 91久久夜色精品国产九色| 老司机午夜精品视频在线观看| 午夜精品久久久久久久男人的天堂| 亚洲区免费影片| 亚洲夫妻自拍| 黄色在线一区| 国产日韩欧美综合一区| 国产精品va| 欧美午夜一区二区福利视频| 欧美精品成人| 欧美日本亚洲视频| 欧美日韩精品二区| 欧美日韩国产在线播放| 欧美欧美天天天天操| 欧美美女操人视频| 欧美色欧美亚洲另类二区| 欧美日韩国产麻豆| 欧美日韩免费区域视频在线观看| 欧美黄色日本| 欧美日韩国产综合网| 欧美精品一区二区三区在线看午夜 | 免费欧美在线| 久热精品视频在线观看| 久久久91精品国产一区二区三区 | 欧美视频在线一区| 欧美色123| 国产精品午夜av在线| 国产精品专区第二| 国产亚洲制服色| 一区二区三区在线视频免费观看| 亚洲成色999久久网站| 在线日韩成人| 99视频精品在线| 亚洲一区二区精品视频| 亚洲女女女同性video| 欧美一区二区三区四区在线观看| 欧美在线关看| 欧美激情视频在线播放| 亚洲欧洲综合另类| 在线亚洲高清视频| 性色av一区二区三区红粉影视| 久久精品色图| 欧美电影在线观看| 国产精品视频yy9299一区| 国产一区二区三区直播精品电影| 亚洲福利视频一区| 亚洲香蕉视频| 男人的天堂亚洲在线| 91久久精品久久国产性色也91 | 欧美成人免费全部观看天天性色| 亚洲人成绝费网站色www| 一区二区三区日韩欧美| 久久国产66| 欧美四级在线观看| 国外成人在线视频网站| 99在线精品免费视频九九视| 久久精品国产综合精品| 亚洲精品日产精品乱码不卡| 欧美亚洲免费在线| 欧美区一区二| 在线看日韩av| 午夜精品久久久久久久久久久久 | 久久久7777| 亚洲精品久久久久久久久久久| 亚洲午夜精品在线| 欧美激情综合在线| 国产一区高清视频| 亚洲综合99| 亚洲激情成人网| 久久久综合视频|