POJ 11,604 Edge shape inequality optimization dp Post Office

Source: Internet
Author: User

D (I, j) represents the minimum cost required to cover the former J villages with the I post Office

Then there is a state transition equation: D (i, j) = min{D (i-1, K) + W (k+1, J)}

Where the value of W (i, J) can be preprocessed.

The following is the code for optimization of quadrilateral inequalities:

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5 using namespacestd;6 7 Const intMAXP = -+Ten;8 Const intMAXV = -+Ten;9 Const intINF =0x3f3f3f3f;Ten  One intN, M; A  - intA[MAXV], SUM[MAXV]; - intD[MAXP][MAXV], S[MAXP][MAXV]; the  - intWintXinty) - { -     intT = (x + y)/2; +     return(t-x) * a[t]-(sum[t-1]-sum[x-1]) + (Sum[y]-sum[t])-(Y-T) *A[t]; - } +  A intMain () at { -      while(SCANF ("%d%d", &n, &m) = =2) -     { -          for(inti =1; I <= N; i++) scanf ("%d", A +i); -          for(inti =1; I <= N; i++) Sum[i] = sum[i-1] +A[i]; -  inmemset (D,0x3f,sizeof(d)); -          for(inti =1; I <= N; i++) {d[1][i] = W (1, i); s[1][i] =0; } to          for(inti =2; I <= m; i++) +         { -s[i][n+1] =N; the              for(intj = N; J > i; j--) *             { $                  for(intK = s[i-1][J]; K <= s[i][j+1]; k++)Panax Notoginseng                 { -                     if(d[i-1][k] + W (k +1, j) <D[i][j]) the                     { +S[I][J] =K; AD[I][J] = d[i-1][k] + W (k +1, j); the                     } +                 } -             } $         } $printf"%d\n", D[m][n]); -     } -  the     return 0; -}
code June

POJ 11,604 Edge shape inequality optimization dp Post Office

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.