POJ 1015 Jury compromise dp+ record path

Source: Internet
Author: User

Look for each point can be transferred out of the state to go back to the root to remove all the points can be transferred to heavy.

This can be done when the distance from the root is small. (Faint feeling there is a bug, or the same to do out of the first. )


#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <cstring> #include < algorithm> #include <iostream> #include <queue> #include <vector>template <class t>inline    BOOL Rd (T &ret) {char c; int sgn;    if (C=getchar (), c==eof) return 0; while (c!= '-' && (c< ' 0 ' | |    C> ' 9 ')) C=getchar ();    sgn= (c== '-')? -1:1;    ret= (c== '-')? 0: (c ' 0 ');    while (C=getchar (), c>= ' 0 ' &&c<= ' 9 ') ret=ret*10+ (c ' 0 ');    RET*=SGN; return 1;}        Template <class t>inline void pt (T x) {if (x <0) {Putchar ('-');    x =-X;    } if (X>9) pt (X/10); Putchar (x%10+ ' 0 ');} const int N = 205;const int M = 25;using namespace Std;int N, M;int a[n], B[n];int dp[m][805], pre[m][805], Id[m][805];boo    L vis[n];vector<int>path;void Output_path () {sort (Path.begin (), Path.end ()); for (int i = 0; i < (int) path.size (); i++) printf ("%d", Path[i]);p UTS ("");    void find (int x, int y) {path.clear (); WhiLe ( -1! = Pre[x][y]) {path.push_back (id[x][y]);        Vis[id[x][y]] = 1;        int tx = pre[x][y]/1000;        int ty = pre[x][y]%1000; x = TX;    y = ty;    }}const int mov = 400;void work () {memset (DP,-1, sizeof DP); Dp[0][mov] = 0;    Pre[0][mov] =-1;            for (int i = 0, i < m; i++) for (int j = 0; J <=; J + +) {if ( -1 = = Dp[i][j]) continue;            memset (Vis, 0, sizeof vis);        Find (I, j);            Output_path ();                    for (int k = 1; k <= N; k++) if (0 = = Vis[k]) {int tmp = a[k]-b[k];  if (Dp[i+1][j+tmp] < DP[I][J] + a[k]+b[k]) {dp[i+1][j+tmp] =                        DP[I][J] + a[k]+b[k];                        PRE[I+1][J+TMP] = i*1000+j;                    ID[I+1][J+TMP] = k;    }}}}int Main () {int Cas = 1; while (~SCANF ("%d%d", &n, &m), n+m) {for (int i = 1; i <= N;        i++) Rd (A[i]), RD (B[i]);        printf ("Jury #%d\n", cas++);        Work ();        int ans =-1; for (int i = n; i <=; i++) if ( -1! = Dp[m][i] | |-1! = Dp[m][800-i]) {if (dp[m                ][i] > Dp[m][800-i]) ans = i;                else ans = 800-i;            Break } printf ("Best jury have value%d for prosecution and value%d for defence:\n", (dp[m][ans]+ans-400)/2, (dp[m][ans]-        ans+400)/2);        Find (M, ans);        Output_path ();    Puts (""); } return 0;}


POJ 1015 Jury compromise dp+ record path

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.