1. 程式人生 > >洛谷10月月賽Round.1 A.絲綢之路

洛谷10月月賽Round.1 A.絲綢之路

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cctype>
using namespace std;
inline void read(int& x)
{
	char _c = getchar();x = 0;bool flag = false;
	while(!isdigit(_c)){if(_c=='-')flag=true;_c=getchar();}
	while(isdigit(_c)){x=x*10+_c-'0';_c=getchar();}
	if(flag)x=-x;
}
#define maxn 1010
int n,m,ans = (1<<30);
int d[maxn],c[maxn];
int dp[maxn][maxn];
int main(void)
{
	read(n),read(m);
	for(int i=1;i<=n;i++)read(d[i]);
	for(int i=1;i<=m;i++)read(c[i]);
	for(int i=1;i<=n;i++)//城市 
	{
		dp[i][i] = dp[i-1][i-1]+d[i]*c[i];
		for(int j=i+1;j<=m;j++)//天 
			dp[i][j] = min(dp[i][j-1],dp[i-1][j-1]+d[i]*c[j]);
	}
	for(int i=n;i<=m;i++)ans = min(ans,dp[n][i]);
	printf("%d\n",ans);
	return 0;
}