Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
按A[i]排序,然后dp第i块搭到j最多剩下数量,79ms#include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct blk{ int h, a, c; bool operator<(blk bb) const{ return a < bb.a; } }A[405]; int N, ans; int dp[40005]; //dp[i][j]:用前i种block搭到j高度时第i种剩下的最多块数,不存在为-1; //dp[i][j] = { c[i]; ( dp[i-1][j] >= 0 ) // { dp[i][j - h[i]] - 1; ( h[i] <= j <= a[i] && dp[i][j - h[i]] > 0 ) // { -1; ( 其他 ) //(重复使用) void solve(){ memset(dp, -1, sizeof(dp)); dp[0] = 0; for(int i = 0; i < N; i++){ for(int j = 0; j <= A[i].a; j++){ if(dp[j] >= 0){ dp[j] = A[i].c; } else if(A[i].h <= j && dp[j - A[i].h] > 0){ dp[j] = dp[j - A[i].h] - 1; } else{ dp[j] = -1; } } } for(int j = A[N-1].a; j >= 0; j--){ if(dp[j] >= 0){ ans = j; return; } } } int main(){ scanf("%d", &N); for(int i = 0; i < N; i++){ scanf("%d%d%d", &A[i].h, &A[i].a, &A[i].c); } sort(A, A + N); solve(); printf("%d\n", ans); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator