Hdu 1300 Pearls (dp)
Question:
A variety of pearls, each purchase must add 10 to the original quantity.
For example, buy 5 pearls with a unit price of 10. The cost is (5 + 10) * 10 = 150. buy 100 pearls with a unit price of 20.
The cost is (100 + 10) * 20 = 2200. The total cost is 150 + 2200 = 2350. if the quality of the pearl is improved. Required 105
The price of pearls is 20. That is to say, both products are of good quality. The total cost is (5 + 100 + 10) * 20 = 2300. In view of the two groups of data. Pearl caPital
I bought high-quality products, and the cost is low!
The question is how to buy at least Pearl!
Train of Thought Analysis:
Dp [I] indicates the optimal solution for buying pearls in I.
Status transfer: dp [I] = min (dp [j] + v) v indicates that the pearls between j-I are all purchased at the price of I.
#include
#include
#include
#include #define maxn 105using namespace std;struct node{ int price,num;}a[105];int dp[maxn];int sum[maxn];int main(){ int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d%d",&a[i].num,&a[i].price); sum[i]=sum[i-1]+a[i].num; } memset(dp,0x3f,sizeof dp); dp[0]=0; for(int i=1;i<=n;i++) { for(int j=0;j