Hdu 1300 Pearls (dp)

Source: Internet
Author: User

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
    
     

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.