码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1176 - 免费馅饼

时间:2014-09-22 09:38:22      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:style   color   io   ar   for   sp   on   c   amp   

题目:接馅饼,天上掉馅饼,活会落在0~10,11个位置上,单位时间可以移动到相邻的格子里;

            问最大能接到多少。

分析:dp,离散化。 

            阶段:时间(离散化的);

            状态:某时间站在当前点,能得到的最大值;

            决策:按照时间计算前一位置可到达当前位置的区间来更新当前点;

说明:初始化 5位置0,其他的都 -10或者其他的就可以了。(2011-09-19 07:56)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct ode
{
    int S,T;
}Node;
Node N[ 100001 ];
int  F[ 100001 ][ 11 ];

int  cmp( const void* a, const void* b )
{
    return ((Node*)a)->T - ((Node*)b)->T;
} 

int main()
{
    int n;
    while ( scanf("%d",&n) && n ) {
        for ( int i = 1 ; i <= n ; ++ i )
            scanf("%d%d",&N[ i ].S,&N[ i ].T);
        
        qsort( &N[ 1 ], n, sizeof( Node ), cmp );
        
        for ( int i = 0 ; i <= 10 ; ++ i )
            F[ 0 ][ i ] = -10;
        F[ 0 ][ 5 ] = 0;
        
        N[ 0 ].T = 0;
        for ( int i = 1 ; i <= n ; ++ i ) {
            for ( int j = 0 ; j <= 10 ; ++ j ) 
               F[ i ][ j ] = F[ i-1 ][ j ];
            for ( int j = 0 ; j <= 10 ; ++ j )
            for ( int k = 0 ; k <= 10 ; ++ k )
                if ( abs( j-k ) <= N[ i ].T - N[ i-1 ].T && F[ i ][ j ] < F[ i-1 ][ k ] )
                    F[ i ][ j ] = F[ i-1 ][ k ];
            F[ i ][ N[ i ].S ] += 1;
        }
        
        int Max = 0;
        for ( int i = 0 ; i <= 10 ; ++ i )
            if ( Max < F[ n ][ i ] )
                Max = F[ n ][ i ];
        
        printf("%d\n",Max);
    }
    return 0;
}

hdu 1176 - 免费馅饼

标签:style   color   io   ar   for   sp   on   c   amp   

原文地址:http://blog.csdn.net/mobius_strip/article/details/39471987

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!