Conditional DP UVA 672 gangsters

Source: Internet
Author: User

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", &AMP;A[I].P);        for (int i=1; i<=n; ++i) scanf ("%d", &AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.