比赛 20140423 评测结果 AAAWWWWWWW
题目名称 电子书狂热者 最终得分 30
用户昵称 digital-T 运行时间 0.165 s
代码语言 C++ 内存使用 0.46 MiB
提交时间 2014-04-23 12:37:06
显示代码纯文本
#include<fstream>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int SIZEN=1010,SIZES=10010,INF=0x7FFFFFFF;
int N,N1,N2,N3;
int book=0;
int book_sum[SIZES];
int origin_cost[SIZES],origin_sum[SIZEN];
int benefit1[SIZES],benefit2[SIZEN];
int a[SIZEN],b[SIZEN],c[SIZEN],d[SIZEN],p[SIZEN],r[SIZEN],s[SIZEN];
void package_1(int n)
{
	benefit1[0]=0;
	for(int i=1;i<=book;i++)
		benefit1[i]=INF;
	for(int i=1;i<=n;i++)
	{
		benefit1[a[i]]=min(benefit1[a[i]],r[i]);
		int temp=a[i]-1;
		while(temp>0 && benefit1[temp]>benefit1[a[i]])
			benefit1[temp]=benefit1[a[i]],temp--;
		for(int j=1;j<=book-a[i];j++)
		{
			if(benefit1[j+a[i]]<benefit1[j]+r[i])continue;
			benefit1[j+a[i]]=benefit1[j]+r[i];
			temp=j+a[i]-1;
			while(temp>0 && benefit1[temp]>benefit1[j+a[i]])
				benefit1[temp]=benefit1[j+a[i]],temp--;
		}
	}
}
void package_2(int n)
{
	benefit2[0]=0;
	for(int i=1;i<=book;i++)
		benefit2[i]=INF;
	for(int i=1;i<=n;i++)
	{
		benefit2[b[i]]=min(benefit2[b[i]],s[i]);
		int temp=b[i]-1;
		while(temp>0 && benefit2[temp]>benefit2[b[i]])
			benefit2[temp]=benefit2[b[i]],temp--;
		for(int j=1;j<=N-b[i];j++)
		{
			if(benefit2[j+b[i]]<benefit2[j]+s[i])continue;
			benefit2[j+b[i]]=benefit2[j]+s[i];
			temp=j+b[i];
			while(temp>0 && benefit2[temp]>benefit2[j+b[i]])
				benefit2[temp]=benefit2[j+b[i]],temp--;
		}
	}
}
int F[SIZEN];
void work()
{
	for(int i=0;i<N;i++)
	{
		for(int j=i+1;j<=N;j++)
		{
			F[j]=min(F[j],F[i]+benefit1[book_sum[j]-book_sum[i]]);//套餐1中获利
			F[j]=min(F[j],F[i]+benefit2[j-i]);//套餐2中获利
			F[j]=min(F[j],F[i]+(origin_sum[j]-origin_sum[i]));//从原价获利
		}
	}
	printf("%d\n",F[N]);
}
int main()
{
	freopen("zealot.in","r",stdin);
	freopen("zealot.out","w",stdout);
	scanf("%d",&N);
	while(N)
	{
		book=0;
		book_sum[0]=0;
		for(int i=1;i<=N;i++)
		{
			scanf("%d",&d[i]);
			book+=d[i];
			book_sum[i]=book_sum[i-1]+d[i];
		}
		//====================================================================================
		scanf("%d",&N1);
		for(int i=1;i<=N1;i++)
		{
			scanf("%d %d",&c[i],&p[i]);
		}
		F[0]=0;
		int temp=1,cost;
		for(int i=1;i<=N;i++)
		{
			if(temp<=N1 && c[temp]==i)
			{
				cost=p[temp];
				temp++;
			}
			F[i]=F[i-1]+cost*d[i];//原价
			origin_sum[i]=F[i];
		}
		//====================================================================================
		scanf("%d",&N2);
		for(int i=1;i<=N2;i++)
		{
			scanf("%d %d",&a[i],&r[i]);
		}
		package_1(N2);
		//====================================================================================
		scanf("%d",&N3);
		for(int i=1;i<=N3;i++)
		{
			scanf("%d %d",&b[i],&s[i]);
		}
		package_2(N3);
		work();
		scanf("%d",&N);
	}
	return 0;
}