标签:something pac nbsp tom blocks define eth else i++
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 4740 Accepted Submission(s):
1319
#define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<algorithm> #include<string> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; typedef long long ll; const int N_MAX = 1000 + 5; ll dp[N_MAX]; int n; struct Cube { ll w, l,h; int id; bool operator <(const Cube&b) { if (this->l != b.l)return this->l < b.l; else if(this->w!=b.w) return this->w < b.w; else return this->id > b.id; } }cube[N_MAX]; bool judge(const Cube& a,const Cube& b) {//b要堆在a上面 if (b.id == 0)return b.l >= a.l&&b.w >= a.w; if (b.id == 1)return (b.l >= a.l&&b.w > a.w) || (b.l > a.l&&b.w >= a.w); return b.l > a.l&&b.w > a.w; } void Dp() { for (int i = 0; i < n;i++) { dp[i] = cube[i].h; } for (int i = 1; i < n;i++) {//每次cube[i]要堆在最上面 for (int j = 0; j < i;j++) { if (judge(cube[j], cube[i]))dp[i] = max(dp[i], dp[j] + cube[i].h); } } ll sum = *max_element(dp, dp + n); printf("%I64d\n",sum); } int main() { while (scanf("%d",&n)&&n) { for (int i = 0; i < n;i++) { scanf("%I64d%I64d%I64d%d",&cube[i].l,&cube[i].w,&cube[i].h,&cube[i].id); if (cube[i].l < cube[i].w)swap(cube[i].l, cube[i].w); } sort(cube, cube + n); Dp(); } return 0; }
poj 4001 To Miss Our Children Time
标签:something pac nbsp tom blocks define eth else i++
原文地址:http://www.cnblogs.com/ZefengYao/p/7045885.html