HDU 1300 PEARLS--DP

Source: Internet
Author: User

Test instructions: There are different grades of pearls, the price is different, now list the need to buy pearls, to spend the least money (can buy high-grade to replace low-grade)

Analysis: Dp[i] represents the minimum amount of money to spend from the lowest level to the I level, dp[i]=min (Dp[j]+v) v is the money from j+1 to i all buy I grade flowers. Requires a triple loop.

Code:

#include <iostream> #include <algorithm> #include <cstdio> #define INF 1000000007using namespace std; int t,n;int a[2000],b[2000];int dp[2000];int min (int p,int q) {return p<q?p:q;} int DP () {for (Int. i=0;i<=n;i++) dp[i]=inf;dp[0]=0;for (int i=1;i<=n;i++) {for (int j=0;j<i;j++) {int v=0;for (int) k=j+1;k<=i;k++)    v+=a[k];    v= (V+10) *b[i];    Dp[i]=min (Dp[j]+v,dp[i]);}} return dp[n];} int main () {cin>>t;while (t--) {cin>>n;for (int i=1;i<=n;i++) cin>>a[i]>>b[i];cout<< DP () <<endl;}}


HDU 1300 PEARLS--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.