POJ 1260 Pearls Simple DP

Source: Internet
Author: User

1, POJ 1260

2, Link: http://poj.org/problem?id=1260

3, Summary: Do not understand DP, read the http://www.cnblogs.com/lyy289065406/archive/2011/07/31/2122652.html

Test instructions: Pearls, give demand, unit price, require the minimum amount of money can buy the same quantity, the same (or higher) quality of pearls.

grasp the test instructions, 1, the input, the pearl price after input must be more expensive than the previous input. 2, with high quality pearls instead of low quality.

#include <iostream>#include<cstring>#include<cmath>#include<queue>#include<algorithm>#include<cstdio>using namespacestd;#defineMin (A, b) a<b?a:b#defineLL Long Long#defineINF 0x3f3f3f3fConst intn=100100;intMain () {intCas,c; inta[1010],p[1010]; intsum[1010],dp[1010];//Sum[i] denotes the first Class I and, Dp[i] represents the optimal solution to Class Iscanf"%d",&CAs);  while(cas--) {scanf ("%d",&c); sum[0]=0;  for(intI=1; i<=c;i++) {scanf ("%d%d",&a[i],&P[i]); Sum[i]=sum[i-1]+A[i]; } dp[0]=0;  for(intI=1; i<=c;i++) {Dp[i]=dp[i-1]+ (a[i]+Ten) *p[i];//first to assign an initial value that is not optimized             for(intj=0; j<i;j++) {Dp[i]=min (dp[i],dp[j]+ (sum[i]-sum[j]+Ten) *p[i]);//key, each contrast optimization, dp[j]+ (sum[i]-sum[j]+10) *p[i]) namely interval I two parts, the former J is the optimal solution dp[j],j to I is (SUM[I]-SUM[J]+10) *p[i])}} cout<<dp[c]<<Endl; }    return 0;}
View Code

POJ 1260 Pearls Simple DP

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.