• <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>

            coreBugZJ

            此 blog 已棄。

            Suneast’s blocks , FZU 2011年3月月賽之 B, FZU 2011

            Problem 2011 Suneast’s blocks

            Time Limit: 1000 mSec    Memory Limit : 32768 KB

            Problem Description

            Suneast loves playing with blocks so much. He has many small triangle blocks:

            He always likes using these small block to make a bigger one:

            The size of the small triangle is 1 and different block has different color, each color is expressed using an UPPER case alpha, so we can represent the big triangle above as the figure shows on the right.('~' means BLANK here)

            Now, Suneast want to know, what is the size of the largest sub-strangle with the same color within the bigger one.

            Input

            The first line of the input data is an integer number T, represent the number of test cases.

            The first line of each test case has an integer N (1<=n<=100), means the height of the big triangle. Then following N lines, each line has exactly 2*i-1 UPPER case letters represent the small triangle.

            Output

            For each test case, output a single line “Case %d: The largest block is %d.”, the first %d means the current case index, and the second %d is the size of the largest block.

            Sample Input

            3
            3
            A
            BCD
            EFDDD
            4
            A
            CCA
            CAAAC
            CACACAC
            4
            T
            ORZ
            DAXIA
            YAYAMAO

            Sample Output

            Case 1: The largest block is 4.
            Case 2: The largest block is 4.
            Case 3: The largest block is 1.

            Source

            FOJ有獎(jiǎng)月賽-2011年03月


            動(dòng)態(tài)規(guī)劃,利用子問(wèn)題,向上,向下。。。


             1 #include <stdio.h>
             2 #include <string.h>
             3 
             4 #define  L  209
             5 
             6 int n, f[ L ][ L ], g[ L ][ L ];
             7 char  tri[ L ][ L ];
             8 
             9 int checkF( int i, int j ) {
            10         int a = ( (tri[i+1][j-1]==tri[i][j]) ? f[i+1][j-1] : 0 );
            11         int b = ( (tri[i+1][j+1]==tri[i][j]) ? f[i+1][j+1] : 0 );
            12         int c = ( a < b ? a : b );
            13         return f[ i ][ j ] = ( (tri[i+1][j]==tri[i][j]) ? (c+1) : 1 );
            14 }
            15 
            16 int checkG( int i, int j ) {
            17         int a = ( (tri[i-1][j-1]==tri[i][j]) ? g[i-1][j-1] : 0 );
            18         int b = ( (tri[i-1][j+1]==tri[i][j]) ? g[i-1][j+1] : 0 );
            19         int c = ( a < b ? a : b );
            20         return g[ i ][ j ] = ( (tri[i-1][j]==tri[i][j]) ? (c+1) : 1 );
            21 }
            22 
            23 int solve() {
            24         int i, j, h = 0, tmp, ans = 0;
            25         for ( i = n; i >= 1--i ) {
            26                 for ( j = n-i+1; j <= n+i-1; j+=2 ) {
            27                         tmp = checkF( i, j );
            28                         if ( tmp > h ) {
            29                                 h = tmp;
            30                         }
            31                 }
            32         }
            33         for ( i = 2; i <= n; ++i ) {
            34                 for ( j = n-i+2; j <= n+i-1; j+=2 ) {
            35                         tmp = checkG( i, j );
            36                         if ( tmp > h ) {
            37                                 h = tmp;
            38                         }
            39                 }
            40         }
            41         for ( i = 1; i <= h; ++i ) {
            42                 ans += i + i - 1;
            43         }
            44         return ans;
            45 }
            46 
            47 char next() {
            48         char ch;
            49         do {
            50                 ch = getchar();
            51         } while ( (ch<'A'|| ('Z'<ch) );
            52         return ch;
            53 }
            54 
            55 int main() {
            56         int td, cd = 0, i, j;
            57         scanf( "%d"&td );
            58         while ( td-- > 0 ) {
            59                 memset( tri, 0sizeof(tri) );
            60                 memset( f, 0sizeof(f) );
            61                 memset( g, 0sizeof(g) );
            62                 scanf( "%d"&n );
            63                 for ( i = 1; i <= n; ++i ) {
            64                         for ( j = n-i+1; j <= n+i-1++j ) {
            65                                 tri[ i ][ j ] = next();
            66                         }
            67                 }
            68                 printf( "Case %d: The largest block is %d.\n"++cd, solve() );
            69         }
            70         return 0;
            71 }
            72 


            posted on 2011-03-20 19:01 coreBugZJ 閱讀(1264) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): ACM

            国产精品成人99久久久久91gav| 精品久久久久久无码不卡| 久久久久久毛片免费播放| 久久久久人妻精品一区| 91精品国产综合久久四虎久久无码一级 | 久久久国产精华液| 久久久久亚洲精品日久生情| 久久久无码精品亚洲日韩蜜臀浪潮| 国产欧美久久一区二区| 亚洲国产精品无码久久九九| 久久亚洲国产成人精品性色| 久久香蕉一级毛片| 久久精品国产久精国产果冻传媒| 久久精品国产99国产电影网| 久久热这里只有精品在线观看| 精品久久久久久国产91| 狠狠色丁香久久婷婷综合| 久久精品中文字幕第23页| 成人久久综合网| 狠狠色噜噜色狠狠狠综合久久| 久久精品国产第一区二区| 国产欧美久久一区二区| 色88久久久久高潮综合影院| 亚洲人AV永久一区二区三区久久| 国产成人精品免费久久久久| 亚洲精品无码久久久| 久久久综合香蕉尹人综合网| 免费观看久久精彩视频| 久久精品国产亚洲av日韩| 99久久99久久精品国产片果冻| 日韩欧美亚洲国产精品字幕久久久| 72种姿势欧美久久久久大黄蕉| 亚洲AV日韩精品久久久久久| 久久久久久久97| 久久精品国产色蜜蜜麻豆| 久久精品国产亚洲av麻豆蜜芽| 精品久久久久久久国产潘金莲| 亚洲欧美日韩精品久久亚洲区| 久久九色综合九色99伊人| 亚洲精品无码久久毛片| 亚洲国产天堂久久久久久|