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