Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 4075 Accepted Submission(s): 1063
卡了一下check,在宽>长那里 。
#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> #include <cstring> #include <vector> #include <map> #include <vector> #include <queue> using namespace std ; typedef long long LL ; typedef pair<int,int> pii; #define X first #define Y second const int N = 1010; struct Blocks { LL a , b , c , d , area ; bool operator < ( const Blocks &A ) const { if( a != A.a ) return a < A.a ; else if( b != A.b ) return b < A.b ; else return d > A.d ; } }e[N]; LL dp[N] ; int main () { #ifdef LOCAL freopen("in.txt","r",stdin); #endif // LOCAL int _ , cas =1 , n ; while( cin >> n && n ) { memset( dp , 0 , sizeof dp ); for( int i = 0 ; i < n ; ++i ) { cin >> e[i].a >> e[i].b >> e[i].c >> e[i].d ; if(e[i].a > e[i].b ) swap(e[i].a, e[i].b ); e[i].area = e[i].a * e[i].b ; } sort( e , e + n ) ; for( int i = 0 ; i < n ; ++i ) { dp[i] = e[i].c ; for( int j = 0 ; j < i ; ++j ) { if( e[i].d == 0 && e[j].a <= e[i].a && e[j].b <= e[i].b ) dp[i] = max( dp[i] , dp[j] + e[i].c ); if( e[i].d == 1 && e[j].a <= e[i].a && e[j].b <= e[i].b && e[j].area < e[i].area ) dp[i] = max( dp[i] , dp[j] + e[i].c ); if( e[i].d == 2 && e[j].a < e[i].a && e[j].b < e[i].b ) dp[i] = max( dp[i] , dp[j] + e[i].c ); } } LL ans = 0 ; for( int i = 0 ; i < n ; ++i ) ans = max( ans , dp[i] ); cout << ans << endl ; } }
hdu 4001 To Miss Our Children Time( sort + DP )
原文:http://www.cnblogs.com/hlmark/p/4296757.html