比赛 20090916练习赛 评测结果 AAWWWAWTTT
题目名称 任务安排 最终得分 30
用户昵称 magic 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2011-09-21 19:58:40
显示代码纯文本
#include<iostream>
#include<cstdio>
#define maxlong 1000000
using namespace std;
	int ti[5005];
	int fi[5005];
	int times[5005];
	int fee[5005];
	int f[5005][5005];
	int n,s,ans;
int min(int x,int y);
int min(int x,int y)
{
	if (x<y) return x;else return y; 
}
int main()
{
	freopen("batch.in","r",stdin);
	freopen("batch.out","w",stdout);
	scanf("%d%d",&n,&s);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d",&ti[i],&fi[i]);
		times[i]=times[i-1]+ti[i];
		fee[i]=fee[i-1]+fi[i];
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=i;j++)
		{
			f[i][1]+=(times[i]+s)*fi[j];
			
		}
	}
	for (int i=2;i<=n;i++)
	{
		for (int j=2;j<=i;j++)
		{
			f[i][j]=maxlong;
			for (int k=1;k<=i-1;k++)
			{
				if (j-1<=k)
				{
				f[i][j]=min(f[i][j],f[k][j-1]+(j*s+times[i])*(fee[i]-fee[k]));
				}
			}
		}
	}
	ans=maxlong;
	/*for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			printf("%d ",f[i][j]);
		}
		printf("\n");
	}*/
	for (int i=1;i<=n;i++)
	{
		ans=min(ans,f[n][i]);
	}
	printf("%d",ans);
	return 0;
}