Topic Portal
Test instructions: N gangsters into the hotel, can vary the width of the door, the range [0, K], each gangster entered the door in ti time, stature si, after entering the success value of Pi, ask the maximum success value
Analysis: First according to the order of the door time, Dp[i][j] indicates the first gangster in the door size of J when the maximum success of the door, then the state transfer equation: dp[i][j] = dp[i-1][k] + A[I].P condition is the gate size from K to J time difference is less than I and ii-1 people door difference
Harvesting: This type of conditional DP transfer I classify as conditional DP
Code:
/************************************************* author:running_time* Created time:2015-8-31 16:19:35* File Na Me:UVA_672.cpp ************************************************/#include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string > #include <vector> #include <queue> #include <deque> #include <stack> #include <list># Include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime>using namespace std; #define Lson L, Mid, RT << 1#define Rson mid + 1, R, RT << 1 | 1typedef long ll;const int N = 1e2 + 10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;struct people {int T , p, S; BOOL Operator < (const people &r) Const {return T < r.t; }}a[n];int Dp[n][n];int Main (void) {int T; scanf ("%d", &t); while (t--) {int n, door, time;scanf ("%d%d%d", &n, &door, &time); for (int i=1; i<=n; ++i) scanf ("%d", &a[i].t); for (int i=1; i<=n; ++i) scanf ("%d", &A[I].P); for (int i=1; i<=n; ++i) scanf ("%d", &A[I].S); Sort (a+1, a+1+n); Memset (DP,-1, sizeof (DP)); int ans = 0; Dp[0][0] = 0; for (int i=1, i<=n; ++i) {for (Int. j=0; j<=door; ++j) {for (int k=0; k<=door; ++k) {if (dp[i-1][k] = = 1 | | ABS (J-K) > a[i].t-a[i-1].t) continue; if (A[i].s = = J && j) {Dp[i][j] = max (Dp[i][j], dp[i-1][k] + A[I].P); } else {Dp[i][j] = max (Dp[i][j], dp[i-1][k]); } ans = max (ans, dp[i][j]); }}} printf ("%d\n", ans); if (T) puts (""); } return 0;}
Conditional DP UVA 672 gangsters