vijos 1235 天堂的馈赠

vijos 1235 天堂的馈赠

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;

const int INF =- 0x7FFFFFFF;
int W , H ,P ,N , T;
int Ans1 , Ans2;
int A [ 2100 ][ 550 ];
int F [ 2100 ][ 550 ];
int main()
{
    scanf( "%d%d%d%d" , & W , &P , & H , &N);
    memset( A , 0 , sizeof( A)); Ans2 = T = 0;
    for( int i = 1; i <=N; ++ i ){
        int t , w , v ,s;
        scanf( "%d%d%d%d" , & t , & w , & v , &s);
        if( H % v != 0 ){ Ans2 +=s; continue; }
        if( t + H / v > T) T = t + H / v;
        if( t + H / v < abs(P - w )){ Ans2 +=s; continue; }
        A [ t + H / v ][ w ] +=s;
    }
    for( int i = 0; i <= T; ++ i)
        for( int j = 1; j <= W; ++ j)
            F [ i ][ j ] = INF;
    Ans1 = F [ 0 ][P ] = A [ 0 ][P ];
    for( int i = 1; i <= T; ++ i)
        for( int j = 1; j <= W; ++ j ){
            for( int k =- 1; k <= 1; ++ k)
                if( j - k > 0 && j - k <= W && F [ i - 1 ][ j - k ] > F [ i ][ j ])
                    F [ i ][ j ] = F [ i - 1 ][ j - k ];
            F [ i ][ j ] += A [ i ][ j ];
        }
    for( int i = 1; i <= W; ++ i)
        if( F [ T ][ i ] > Ans1) Ans1 = F [ T ][ i ];
    printf( "%d \n %d \n " , Ans1 , Ans2);
    return 0;
}






你可能感兴趣的:(vijos 1235 天堂的馈赠)