P3399 Silk Road, p3399 Silk Road

Source: Internet
Author: User

P3399 Silk Road, p3399 Silk Road
Background

In 138 BC, Zhang was able to go through the western regions. Strengthened the friendly exchanges between the Han Dynasty and countries in the western regions. Since then, a team of camels have traveled on this long road of commerce. They have crossed the mountains and brought China's advanced technologies to Central Asia, Western Asia, and Europe, spread the spices and good horses there into our country. Every time people stare at the desolate desert and smoke alone, they will not worry about the prosperity of commerce and culture in the past ......

Description

The little hamster took the goods and sent them to rest in peace from China. The Silk Road included a total of N + 1 cities, where city 0 was the start of Changan and city N was the end of Baghdad. The destination must be reached within M days. One day can be taken from one city to another. The distance from I-1 city to I city is Di.

As we all know, continuous drive is very hard, so when a hamster is in a city, you can have the following options:

  • Mobile: Heading for the next city

  • Rest: Stay in the original city

The desert weather is changing. When the weather is not good, it will encounter many difficulties. We record the severe climate value of day j (1 <= j <= M) of day M as Cj. Moving from a city in I-1 to a city in the j-day process requires the fatigue of Di * Cj.

However, the hamster still has the right to avoid bad weather and rest will not consume fatigue values. Now he wants to know the minimum fatigue value of the entire trip.

Input/Output Format

Input Format:

 

2 integers N, M in the first row

One integer Dj in each row of N consecutive rows

One integer per row in M consecutive rows, Cj

 

Output Format:

 

An integer that represents the minimum fatigue.

 

Input and Output sample input sample #1:
3 51025155030154030
Output sample #1:
1125
Description

The time limit for this question is 1 s, and the memory limit is 128 M. Because the new evaluation machine speed is close to the NOIP evaluation machine speed, please pay attention to the influence of the constant problem.

1st days off

2nd days 0-> 1 fatigue value 10 × 30 = 300.

3rd days 1-> 2 fatigue value 25 × 15 = 375.

4th days off

5th days 2-> 3 fatigue value 15 × 30 = 450.

1 Jun N Jun M Jun 1000

1 branch Di, Ci branch 1000

 

Use dp [I] [j] to represent the minimum fatigue value of the city on the j + 1 day;

The decision is clearly stated in the question.

(The code is not written by me, but the general idea is the same. I accidentally lost the one I wrote for special reasons .. ,)

 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 int n,m,d[1001],c[1001],dp[1001][1001]; 5 int main() 6 { 7     cin >> n >> m; 8     for(int i=1;i<=n;i++) 9         cin >> d[i];10     for(int i=1;i<=m;i++)11         cin >> c[i];12     memset(dp,0x3f,sizeof(dp));13     memset(dp[0],0,sizeof(dp[0]));14     for(int i=1;i<=n;i++)15         for(int j=1;j<=m;j++)16             dp[i][j]=min(dp[i][j-1],dp[i-1][j-1]+d[i]*c[j]);17     cout << dp[n][m] << endl;18     return 0;19 }

 

Related Article

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.