Rokua P3399 Silk Road

Source: Internet
Author: User

Topic Background

Zhang Qian in 138 BC had gone through the difficult and dangerous to the western regions. The friendship between the Han Dynasty and the western countries was strengthened. Since then, a team of camel caravan on the long road of trade, they crossed the mountains, the Chinese advanced technology to Central Asia, West Asia and Europe, where the spices, it stumbles sent into our country. Whenever people stare at the desolate desert solitary smoke, all caused the past business, cultural prosperity of reverie ...

Title Description

Small hamster with goods, from China to rest, the Silk Road including the beginning and end of the total n+1 city, No. 0 City is the beginning of Changan, N city is the end of Baghdad. Requires no more than m days to reach the end point. The time of day can be from one city to the next city in succession. From the I-1 city to i the city distance is di.

As we all know, continuous travel is very hard, so the hamster can be in a city when there are the following options:

    • Move: Down a city

    • Rest: Stay in the Old City and not move

The desert weather is changeable, and when the weather is bad, there are many difficulties ahead. We recorded the bad climatic value of M-day's J (1<=j<=m) day as CJ. Moving from I-1 City to I city on the first day of J, it takes DI*CJ fatigue.

However, the hamster still has the option to avoid the more severe weather, rest will not consume fatigue value. Now he wants to know how much fatigue the whole trip will cost.

input/output format

Input format:

First row 2 integers n,m

Consecutive n rows per line an integer DJ

Continuous m line one integer per line CJ

Output format:

An integer representing the minimum fatigue level

input/Output sampleInput Sample # #:
3 51025155030154030
Sample # # of output:
1125
Description

Subject time limit 1s, memory limit 128M, because the new evaluation machine speed is closer to NOIP evaluation machine speed, please pay attention to the effect of constant problem.

1th Day Rest

2nd day 0->1 Fatigue Value 10x30 = 300.

3rd day 1->2 Fatigue Value 25x15 = 375.

4th Day Rest

5th day 2->3 Fatigue Value 15x30 = 450.

1≦n≦m≦1000

1≦di, ci≦1000

#include <iostream>#include<cstdio>#include<cstring>#defineMAXN 2100using namespacestd;intN,M,C[MAXN],D[MAXN],F[MAXN][MAXN];intMain () {memset (F,0x7f,sizeoff); scanf ("%d%d",&n,&m);  for(intI=0; i<=m; i++) f[i][0]=0;  for(intI=1; i<=n;i++) scanf ("%d",&D[i]);  for(intI=1; i<=m;i++) scanf ("%d",&C[i]);  for(intI=1; i<=m; i++)//Analog days for(intj=1; j<=min (i,n); j + +)//Analog City F[i][j]=min (f[i-1][j-1]+d[j]*c[i],f[i-1][j]);//I-1 Day went to the city of J-1, the first i-1 days to stay in the J Cityprintf ("%d",f[m][n]); return 0;}

Rokua P3399 Silk Road

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.